I have a common query about Wordpress Canonical URLs that I can't seem to fix.
The Problem:
My site is loading content correctly at https://example.com/parent/the-url/
However the same page also loads as a duplicate at https://example.com/the-url/ (missing out the page hierarchy and creating duplicate content). Editing either of these posts takes me to the same backend editing page, which means that both URL's are being generated from the same page.
The variation of the page at the incorrect URL ( https://example.com/the-url/ ) has an incorrect layout and additional Wordpress related information on the page including a 'post name' and date which I have not defined myself.
I tried to disable canonical URLs using this code in the child theme 'function.php' file:
remove_filter('template_redirect', 'redirect_canonical');
No luck whatsoever, tested in incognito so there's no cache interference here.
Does anyone know what I'm missing or a way of removing the shorter (incorrect) version of the URL?
Filter to Disable Canonical URLs
add_filter( 'wpseo_canonical', '__return_false' );
Steps to Disabling Yoast Canonicals
Add the code found above to a new link within your functions.php
Hope this help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.