Last active
August 29, 2015 14:11
-
-
Save nicholasohrn/bc3477dd61bfbf3e52e6 to your computer and use it in GitHub Desktop.
Redirect custom post types that are defined to the home page before running any DB queries or anything.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Hook in to the parse_request action to see if any custom post type | |
* variables are present. If so, redirect. | |
**/ | |
function redirect_cpt_to_home($wp) { | |
$redirectable = array('book', 'movie', 'event'); | |
if(in_array($wp->query_vars['post_type'], $redirectable)) { | |
wp_redirect(home_url('/')); | |
exit; | |
} | |
} | |
add_action('parse_request', 'redirect_cpt_to_home'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment