Home > database >  How to stop redirect canonical for a single page
How to stop redirect canonical for a single page

Time:10-27

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;
}

CodePudding user response:

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;
}

CodePudding user response:

/** 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');
  • Related