Custom post type redirect in WordPress


add_action( 'template_redirect', 'aviweb_redirect_post_type' );
function aviweb_redirect_post_type() {
	$queried_post_type = get_query_var('post_type');
	if ( is_single() && 'custom_post' ==  $queried_post_type ) {
		$redirection_url = get_site_url() . '/custom_page';
		wp_redirect( $redirection_url, 301 );
	exit;
	}		
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s