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

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

  • Thank you very much for the question. I needed to redirect all posts of my wordpress site into a new NUXT frontend website. Pasted into the custom plugin I made, and it just works!
    – Imtiaz
    Commented Aug 14, 2020 at 17:45

1 Answer 1


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/" ?
    – JoaMika
    Commented Jan 3, 2019 at 19:40
  • Test for slug or post ID (testing for post ID is best - most reliable) Commented Jan 3, 2019 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 ?
    – JoaMika
    Commented Jan 4, 2019 at 11:13
  • Yes - all posts have their IDs assigned - if the post is displayed, then you have access to all its properties. Commented Jan 4, 2019 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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