Categories
Code Snippets PHP Wordpress

Redirect for a Specific Page on WordPress

Here’s a snippet of code to redirect users who land on a specific page of your wordpress site.

You will need the page id. Add it to your functions.php file.

The code below redirect users to my site. 🙂

function redirect_to_another_page() {
   $page_id_to_redirect = 119; //enter page id here
   $destination = 'https://kimberleydurrant.com'; //enter destination url here

   if ( is_page($page_id_to_redirect) ) {
      wp_redirect( $destination, 301 );
      exit;
   }
}
add_action( 'template_redirect', 'redirect_to_another_page' );

Leave a Reply