0

I am using this code so that when the user visits the old permalink, he gets redirected to the new one.

add_action( 'template_redirect', 'redirect_to_external_url' );
function redirect_to_external_url() {
    if ( is_page( 'https://www.domain.com/brands/haute-couture/' ) ) {
      wp_redirect( 'https://www.domain.com/brands/fashion/', 301 ); 
    exit;
    }
}

However, this doesn't seem to work. I am also using Nginx. Any help would be much appreciated.

0

There is nothing wrong with wp_redirect part of your code...

But... is_page function can’t be used with URL address... You should pass “Page ID, title, slug, or array of such” as stated in documentation.

  • so how could i test if the slug is "brands/haute-couture/" ? – Joanna Mikalai Jan 3 at 19:40
  • Test for slug or post ID (testing for post ID is best - most reliable) – Krzysiek Dróżdż Jan 3 at 22:53
  • But if a user finds this page on google: domain.com/brands/haute-couture - will this be associated with the post ID by wordpress and be redirected ? – Joanna Mikalai Jan 4 at 11:13
  • Yes - all posts have their IDs assigned - if the post is displayed, then you have access to all its properties. – Krzysiek Dróżdż Jan 4 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.