Disable the Single Post View For a Custom Post Type in WordPress

Here’s a handy code snippet, which allows developers to disable single post view for a specific custom post type in WordPress.

Quick Tip : Disable Comment Notifications in WordPress

All you need to do is copy the following code and paste it inside your functions.php file located inside your theme folder.

add_action( 'template_redirect', 'wpse_128636_redirect_post' );

function wpse_128636_redirect_post() {
  $queried_post_type = get_query_var('post_type');
  if ( is_single() && 'my_post_type' ==  $queried_post_type ) {
    wp_redirect( home_url(), 301 );
    exit;
  }
}

Note: Replace my_post_type with your own custom post type name.

0 Comments

Leave a Comment.