“Only” is one of those words that never quite feels at home anywhere in a sentence. It is frequently misplaced, although our brains are wired in such a way that most of the time we unconsciously relocate it and interpret the sentence correctly.
“Only” can be an adjective or an adverb. As such, it should be placed immediately in front of the word it restricts. Otherwise, the sentence changes meaning.
Let’s take, for example, the title line from Gene Pitney’s 1962 hit, “Only Love Can Break a Heart.”
As it is written, the sentence says that nothing else except love can cause heartbreak. Fair enough, although maybe not exactly true.

But what if we change it to say, “Love only can break your heart”? The sentence now informs the reader that love can do only one thing to your heart — break it — but nothing else.
Change it again to “Love can only break your heart.” Then the sense of the sentence changes to a warning to stay away from love, which is certain to cause you grief.
Another morph and “Love can break only your heart” — good news for your liver, spleen and other organs.
How about, “Love can break your only heart” — bad news for those without a spare.
And finally, “Love can break your heart only” again, glad tidings for the rest of your body, although an awkward way to put it.
Note: As is often the case with grammar, correct placement can make everyday speech sound stilted or awkward — the sort of thing up with which many people will not put.
So in formal writing at least, in order to keep “only” from being lonely, just let it cozy up to the word it wants to be close to. (Just for the record, “just” should be treated similarly.)