I already created the Canonical URL for Dynamic Page using below code
My code:
function aioseo_filter_canonical_url( $url ) {
$pageurl="medical-billing-coding-services/";
$statecode=mp_usstate_slug_shortcode();
if ( is_singular() && strpos($url,$pageurl)!==false && !empty($statecode)) {
$newurl=substr($url,0,-1);
$newurl .= '-' . $statecode . '/';
return $newurl;
}
return $url;
}
Output is:
<link rel="canonical" href="https://example.com/medical-billing-coding-services-alabama/" />
I need the canonical URL should appear like below, which means state name should appear before
https://example.com/alabama-medical-billing-coding-services/
I want to use the same code to make the URL change like above. How to change it?