Change cannonical URL after changing url with add_rewrite_rule()


So, I’m making a plugin for some niche application for my customer which involves a table with data, and I created a page within the plugin to show more in-depth information about the table row.

This is how I’m making the rewrite:

function mytableplugin_page_rewrite(){
 $page_slug = 'mytablepluginpage';

 // urls will be in the form
 // /your-page/42/

     'index.php?pagename=' . $page_slug . '&tid=$matches[1]',

But the redirect doesn’t affect the canonical url, so every “mytableplugin” page has the same “mytablepluginpage” canonical URL

I’m not using Yoast SEO plugin, and I don’t want my plugin to depend on it, so, how can I change the canonical link of the page? I want the custom name (mytableplugin != mytablepluginpage) to be kept and the argument to keep on the canonical URL

It’s being a problem because the TranslatePress plugin is using the wrong URL when switching languages, it’s throwing me back into the “mytablepluginpage” page that has no content without the queries.

Thanks in advance!

Miguel Vieira 4 months 0 Answers 11 views 0

Leave an answer