I currently have a shortcode which dynamically swaps out locations on a page to make each page specific to a location.
For example the url
http://mywebsite.com/offers/scotland/
Would make the H1 of my website be
Special Offers Scotland
But now I also want to change the title tag to allow effect search engine optimisation. I am unsure if it’s possible to do this within my shortcode as it will execute within the loop and therefore the header.php has already finished loading.
Any guidance would be greatly appreciated.
You are correct in your thinking that because the loop evaluates after the header you will not be able to get the contents of the loop there.
The easiest way to do this is probably with jQuery. Something like this:
Place this code in your loop, and the page title will be changed on after the document is ready. This may not be a desirable solution however, because some search engines do not evaluate JavaScript. You can use Google Webmaster Tools to see what the page looks like to the Google Crawler.
As an alternate solution, I believe All in One SEO Pack has the functionality that you describe: