Could you please tell me which one of these sentences is correct, or are they both grammatically correct?
This will only happen if you go with me.
This will happen only if you go with me.
Could you please tell me which one of these sentences is correct, or are they both grammatically correct?
This will only happen if you go with me.
This will happen only if you go with me.
The misplaced modifier is a notorious feature that often crops up in English. 'Limiting modifiers', also dubbed 'multi-purpose modifiers' (accurate if not a very helpful classifier), such as only, even (arguably not a limiting modifier), always, almost, nearly, hardly, merely, scarcely, barely, simply, just, at first, and but (in he was but a youth), are frequently misplaced. They should be placed in front of the noun group etc that they are modifying to avoid confusion.
In the given example, only is 'modifying' the dependent clause, if you go with me and hence the safest place for it to be placed is just before this:
This will happen only if you go with me.
However, this sounds rather starchy, and in this case we can get away with placing it in front of the verb (as it can't be read as modifying the verb in this case):
This will only happen if you go with me.
However, with some verbs, modification by 'only' would make sense. In such cases, the switch to the pre-verb position is not advisable (though it is still used), as the primary meaning would change:
He only jogged back to the jeep when he saw the rhinos approaching. {He should have sprinted.}
He jogged back to the jeep only when he saw the rhinos approaching. {He should have started back as soon as he saw them.}
You would normally say:
This will only happen if you go with me.
However there may be other sentences examples where reversing only and happen may read better.
Bill Franke: "idiom" is about natural use of language and not about speech vs. written language. In the 19th century, some artificial rules were introduced into the English language by grammarians with a better grasp of Latin grammar than English grammar. An example is the rule against double negatives. A look at nearly all European languages shows that double negatives are the rule (French, Spanish, etc - je ne sais rien, no tengo nada, etc) - and it seems to me that the local dialects of every part of England had the double negative originally. In fact, in all parts of England, the "uneducated" seem to use the double negative, but self-appointed grammarians decided it was wrong, based on "logic" and a comparison with Latin grammar alone - and their control of the education system means that people like me have grown up saying "I don't know anything" naturally. This overturns the original natural idiom.
Those grammarians tried, but did not succeed, to achieve a similar overturning of the natural idiom in cases such as "it's me". They didn't really understand English grammar - as "me" is the disjunctive pronoun as well as being the object pronoun: "it is I" contains a serious grammatical mistake. But in any case, few people say "it is I", so, unlike the situation with the double negative, they did not manage to overturn natural idiom.
As you can see, whether to say "me" or "I" as the disjunctive pronoun in copula sentences and whether to use the double negative are not questions of speech vs. writing. Idiom - the natural phrasing of the language - is maintained in good writing too. Coming back to the issue of the placing of "only" in the sentence, an unnatural overturning of the natural idiom was also attempted here by 19th-century grammarians attempting to change the language, not codify the language, but change it, in line with their view of "logic" and Latin grammar. If you are correct that people are more likely to shift the position of "only" in writing, that is only because poor grammarians have convinced them, quite wrongly, that natural English idiom is incorrect.
I agree that there is a colloquial register and a formal register, and to that extent an educated person does not write as he speaks. A greater range of vocabulary and more complex sentence structure can be used in writing. But that does not mean that artificial things spliced into the language that were never there in Early Modern English are correct - grammarians with a weak grasp of English idiom attempted to pervert English into a calque of Latin. "This will only happen if you go with me" is by a long way the preferred natural phrase, both in writing and in speech.