So the obvious first question is whether you've looked into an open-jaw ticket (out SFO-BCN, back LON-SFO) and whether that will help you. (Or a circle trip SFO-BCN-LON-SFO.) There are several places you could potentially change planes on the outbound depending on your choice of airline; Heathrow would definitely be a possibility, but Frankfurt might serve you just as well (or better!).
If you're not wedded to United, you could look into US Airways (so you'd still earn United miles) who can get you San Francisco-Philadelphia-Barcelona, or American, who can do San Francisco-JFK-Barcelona.
What you should definitely not be doing is buying separate tickets on full-service airlines from SFO-London and London-Barcelona. It's almost always more expensive to do that than to get a through ticket.
Oh, and it may be (and it may not be!) that you can get a SFO-BCN ticket that allows for a stopover in London. That's well worth exploring.