How to use the Yoast SEO wpseo_canonical filter to set a canonical URL for /, /au/ & /uk/ sites in a MU environment

How would I use wpseo_canonical filter to set a canonical URL for the posts in www.example.com/uk/? E.g. the blog post www.example.com/uk/blog/post-1/ should have a canonical URL of www.example.com/blog/post-1/ I believe. I don’t know if that should be the canonical URL, but if you are asking how can that be done, then this would do it, … Read more

WordPress Redirecting Non Category Pages /page/nnn to their Canonical URLs

This is by design and intentional. WordPress rewrites have become increasingly complex over the years, and many plugins utilise the page endpoint for a page (usually with a template and custom query) – redirecting introduces a potential world of pain. Long story short, it doesn’t matter anyway. WordPress adds <link rel=”canonical /> for pages, so … Read more

Pagination url canonical problem

You have to install Yoast SEO and then add to functions.php: function return_canon () { $canon_page = get_pagenum_link(1); return $canon_page; } function canon_paged() { if (is_paged()) { add_filter( ‘wpseo_canonical’, ‘return_canon’ ); } } add_filter(‘wpseo_head’,’canon_paged’);

Setting custom canonical urls

It depends on how your canonical URLs are being written to the page. In your theme’s header you may find something like: <link rel=”canonical” href=”https://wordpress.stackexchange.com/questions/331598/<?php echo get_permalink(); ?>”> If you are able to edit your theme (or child theme if using a distributed theme) you can put whatever you want there instead. For instance, you … Read more