I need to change the canonical URL dynamically based on my page URL

31 views Asked by At

I need to change the canonical URL dynamically based on my page URL

I have wordpress website and I want one primary service page to be visible for various states in a country. Using rewrite rule & shortcode functionalty I successfully generated pages for various state. Now I want to change the canonical URL for the each state pages.

For example I have primary service page like this - mysite.com/service-page

With that single primary page I have generated the state pages URL's like below:

mysite.com/service-page-new-york

mysite.com/service-page-new-jersey

mysite.com/service-page-georgia

I have canonical URL for all these state page is: mysite.com/service-page/

But I want canonical URL should be based on state name URL's like below:

mysite.com/service-page-new-york

mysite.com/service-page-new-jersey

mysite.com/service-page-georgia

How can I achieve this URL's dynamically?? My website is wordpress and it is not a dynamic website.

I need code for getting dynamic canonical URL for all these state pages.

0

There are 0 answers