Until a few years ago, this part of the offside law was relatively easy. If a player was in an offside position when the ball was kicked, and he subsequently interfered with play, then the offside was given at the place where the player was when the ball was kicked. Since an attacker can't be in an offside position in your own half, that meant the free kick was always in the defending team's own half.
Then the lawmaking committee, in a desperate attempt to prove they are cleverer than everyone who has ever played the game, decided that was all wrong. Now, you can still only be in an offside position in your opponents' half, but you aren't technically offside until you interfere with play. So if you are a yard inside the opponent's half in an offside position, and one of your team plays a suicide ball to a man 30 yards from goal and you dash back an interfere, the opponents get a free kick 30 yards from goal.
It's stupid, but these lawmakers want to keep changing things, because then the fools running the game think they are doing an essential job.