Hiding Custom Post Type from Google?

I have a plugin that uses custom post type for holding content that I pull via a shortcode elsewhere. However on a new site I noticed one of the posts in the CPT started showing up in the google search results. The post isn’t linked anywhere directly. How would that show up there? How can I hide it from showing up in google?

I set public to false, now that just turns the page into the home page. I don’t know that this will completely fix my problem. What else can I do?

register_post_type('mycpt', array(
    'labels' => $labels,
    'public' => false,
    'show_ui' => true,
    'menu_icon' => $icon_svg,
    '_builtin' => false,
    'capability_type' => 'page',
    'hierarchical' => true,
    'rewrite' => false,
    'query_var' => 'mycpt',
    'exclude_from_search' => true,
    'supports' => array(
        'title', 'editor', 'revisions',
    ),
    'show_in_menu' => true,
));

2 Answers
2

If you are using an SEO plugin such as Yoast, it automatically adds all Custom Post Types (and Taxonomies) to the sitemap that is used by Google & other search engines.

You will need to explicitly exclude them from the sitemap e.g in Yoast, this is under the “Post Types”https://wordpress.stackexchange.com/”Taxomonies” tab in the “XML Sitemaps” settings page.

Also don’t forget to remove the links from Google through Webmaster Tools – otherwise you have to wait for Google to re-index your site.

Leave a Comment