1. Home
  2. /
  3. Forum

Forum

How to redirect to ...
 
Notifications
Clear all

How to redirect to another url based upon a template in WordPress

1 Posts
1 Users
0 Reactions
551 Views
(@devsam)
Member Admin
Joined: 5 years ago
Posts: 18
Topic starter  

You can use "template_redirect" to handle any redirects before loading any other resources in WordPress. And, in order to do so... use the below pieace of code.

 

function custom_redirects() {
 
    if ( is_page_template( 'template-appointment.php' ) ) {
		
		if( empty( $_GET['package'] ) ){
		
			wp_redirect( home_url( '/' ) );
			die;
		
		}

    }
 
}
add_action( 'template_redirect', 'custom_redirects' );


Or, simply...

function custom_redirects() {
 
    if ( is_page_template( 'template-appointment.php' ) ) {
		
			wp_redirect( home_url( '/' ) );
			die;

    }
 
}
add_action( 'template_redirect', 'custom_redirects' );

   
Quote
Share:
Reviews & Ratings Get your stoe online with Shopify in 60 minutes Shop Now