I have wordpress website which is based in U.S. and I have a primary service page and it URL is www.example.com/service-page
Using this single primary service page, I rewrite the URL and generated 51 state based URL's like below
www.example.com/service-page-georgia
www.example.com/service-page-florida
www.example.com/service-page-new-york
Each page has different content, but the title of all 51 state page is same "Service Page".
I want to change all the 51 state page titles based on the URL. For example
If I landed on www.example.com/service-page-georgia, the title should be "Service Page Georgia" likewise I want it for all 51 state page.
What shall I do, if I want to get dynamic title for each state based pages.
Below is my code for URL Rewrite:
function mp_rewrite(){
add_rewrite_rule('^(services-page)-([^/]*)/?', 'index.php?pagename=$matches[1]&usstate=$matches[2]','top');
}
//Function to Flush the Rewrite rules
function mp_flush_rewrite_rules()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
//Function to grab the query parameter and store it.
function mp_query_vars($vars){
$vars[] = 'usstate';
return $vars;
}