WordPress – fix canonical URL

This goes into functions.php

CHECK YOUR QUOTES WHEN PASTING

function gallery_canonical($url) {
return site_url($_SERVER[‘REQUEST_URI’]);
}

add_filter( ‘wpseo_canonical’, ‘gallery_canonical’ );

add_filter( ‘wpseo_opengraph_url’, ‘gallery_canonical’ );

Alternate version:

function gallery_canonical($url) {
return site_url($_SERVER[‘REQUEST_URI’]);
}

add_action(‘init’, function() {
add_filter(‘wpseo_canonical’ , ‘gallery_canonical’, 10,1);
add_filter( ‘wpseo_opengraph_url’, ‘gallery_canonical’ );

});

Back to Top