Well, that defys the rule of Spanish not becoming the first language of more countries doesn't. I mean you just got Portugal speaking Spanish. My own ideas were something like Spain having a king that acts like Louis the XIV, and who ends up making Spanish culture and language popular.
Since Portuguese is so close to Spanish, you'd more just fuse Portuguese into Spanish in terms of prestige language, and probably leave Portuguese no stronger than Catalan, if that. That'll add Brazil and the Portuguese Empire to the Spanish-speaking world.
But the main issue with making Spanish more popular is that even if Spain ruled the biggest empire in the world, it was mainly a bunch of resource extraction colonies that barely spoke Spanish since they were most all American Indians to begin with. There's without a doubt a way to make it more prominent, but speaking of French, remember that France was basically the China of Europe in terms of economic, military, demographic, and cultural strength. Spain was a bunch of kingdoms knitted together by inheritance and the Reconquista that happened to find a massive source of wealth that beyond all luck, they managed to conquer.
There's always the chance that a more populated California would just break away from Mexico and form its own country. It's not like the Hispanophone settlers in California had much love to be ruled from distant Mexico City.
Nor for that matter did the ones in New Mexico. Even Texas was a theatre during the Mexican independence wars, which found ample support there although that support would turn to opposition once the Mexico City government failed them as it did in New Mexico--Tejanos fought alongside Anglos in the Texas Revolution, after all.
The easiest way for Spain to gain a huge amount of land in North America (and actually hold it rather than just looking imposing on a map) is to loosen their immigration policy as well as to find the key gold/silver deposits in Colorado, Nevada, California, and Georgia. It's logical why they didn't find the California/Nevada resources, since the natives didn't know of it plus they were remote, but it's interesting Spain never found the gold in Georgia (known by the natives) or in Colorado (Spanish traders with the Plains Indians operated around there as well as the Spanish frontier armies operating against Indians). All four deposits are plausible for Spain to find, which will breath new life into the otherwise disfunctional Mexican North (or if early enough, spur Spanish colonisation of Georgia/Alabama--plenty of agricultural wealth to exploit there if low manpower compared to Latin America, hence where slaves come in).
If the United States had more liberal immigration rules, Spanish might have become much stronger there than in OTL.
As late as the 1920s, a Mexican could just walk across the border and pretend to be on some business or another and not be questioned, and later settle somewhere else in the US, with the US Border Patrol admitting in internal memos about how impossible the Mexican border was to secure. Incidentally, the Border Patrol didn't even exist until 1924 and mainly existed to chase down Chinese entering through Mexico--that's how liberal they were on Mexicans at that point. 10% of Mexicans fled the Mexican Revolution's violence, most going to the US. It seems pretty hard to beat that wave of immigration.
That said, the US could do far more with the Spanish language, like possibly turning it into a second language in parts, maybe even like the Quebec treatment. That seems anathema for an Anglo society, but certainly the former Spanish lands (at the very least New Mexico, and let's expand it to Arizona, California, and Texas) could have Spanish as a second language. But that's not the way to make Spanish more popular globally.