Skip to content

Instantly share code, notes, and snippets.

@nicholasohrn
Last active August 29, 2015 14:11
Show Gist options
  • Save nicholasohrn/bc3477dd61bfbf3e52e6 to your computer and use it in GitHub Desktop.
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.
<?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