404 error – How to disable WordPress Rewriting URL with Nearest Matching Page Slug?


WordPress appears to rewrite URLs, displaying Pages under the incorrect URL.


I have a page called “Emotion” with the slug /emotion/

On the front-end it should appear as the following URL ;

That is, there is a child/parent relationship defined within the Pages section of the website, as shown in that URL.

Unfortunately, wordpress chooses to show anyone the page, no matter what URL you type in


  1. example.com/search/emotion/
  2. example.com/this-parent-doesnt-exist/emotion/
  3. example.com/learning/concepts/emotion/

None of these are real paths. I expect to see a 404 page.

I’ve done research already, and tried the following. The first one used to work in WP versions prior to v6. Neither work.

  1. remove_filter(‘template_redirect’, ‘redirect_canonical’);

  2. add_filter( ‘redirect_canonical’, ‘disable_redirect_canonical’, 10, 2 );
    function disable_redirect_canonical( $redirect_url ) {
    return false;

How do I disable this rewrite rule?

RedWebMan 1 year 2023-02-21T00:42:29-05:00 0 Answers 0 views 0

Leave an answer