This is a problem that I have faced with this blog. I wanted to remove code snippets from search results. The solution is very simple. You just need to add this small piece of code in your functions.php file.

add_action( 'init', 'wpctRemoveCodeSnippetsSearch', 99 );
function wpctRemoveCodeSnippetsSearch() {
    global $wp_post_types;
    if ( post_type_exists( 'custom-post-type' ) ) {
        $wp_post_types['custom-post-type']->exclude_from_search = true;

Please remember to replace 2 instances of custom-post-type by your own custom post type, ex. book.

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *