If your thoughts wander during prayer, Jeremiah Burroughs (1599-1646) has help to offer:
When you go to prayer, account it to be a great work. Set a high price upon your prayer, not as having any excellency in it because it comes from you, but set a high price upon it as a great ordinance of God wherein there is communion with God to be enjoyed and the inflence of God to be conveyed through it. So set a high price on prayer every time you are going to prayer.
"Lord, I am now setting upon a work that is of very great consequence, and much lies upon it. And I would account it to be a sore and a great evil to me if I should lose even this prayer." This would be a special means to compose your spirit and to keep you from wandering as Nehemiah did in Hehemiah 6:3. This is a place that I have sometimes quoted upon such an occasion, when the enemies of Nehemiah who would hinder the building of the temple sent to him that they might talk together. "No," he said, "I am doing a great work so that I cannot come down."
So when the devil and the vanity of your own heart would send you to parley and talk with you, give this answer: "I cannot stand parleying with these things. The work that I am about is a great work." There are very few people who account the work of prayer a great work. If you did, it would greatly help you against the vanity of your thoughts.
From Jeremiah Burroughs, Gospel Worship, pp. 305-306.