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 = ''; //enter destination url here
if ( is_page($page_id_to_redirect) ) {
wp_redirect( $destination, 301 );
add_action( 'template_redirect', 'redirect_to_another_page' );

Leave a Reply

Your email address will not be published. Required fields are marked *