skip to Main Content

The issue I’m having is similar named posts are redirecting to the wrong pages

so urls like

example.com/terms

are redirecting to

example.com/en/terms-of-use

How do I turn off wordpress’s redirect_canonical only for the "terms" page?

Currently what I have

add_filter( 'redirect_canonical', 'disable_redirect_canonical_for_terms', 2, 10 );

function disable_redirect_canonical_for_terms( $redirect_url, $requested_url ) {
    if ( strpos( $requested_url, 'terms' ) !== false ) {
        return false;
    }
    return $redirect_url;
}

2

Answers


  1. You can use is_page. check below code.

    add_filter( 'redirect_canonical', 'disable_redirect_canonical_for_terms', 2, 10 );
    function disable_redirect_canonical_for_terms( $redirect_url, $requested_url ) {
        if( is_page( 'terms' ) ){
            return false;
        }
        return $redirect_url;
    }
    
    Login or Signup to reply.
  2. /** REMOVE CANONICAL FROM SPECIFIC POST IDS **/
    function sp_titles_canonical($html) {
    
        if( is_page( array( 3861, 4006, 4027, 4010 ) ) ) {
            return false;
        }
        else {
          return $html;
        }
    
    }
    add_filter('seopress_titles_canonical','sp_titles_canonical');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search