1

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,
));
  • 1
    Are you using Yoast or a similar SEO plugin? That will automatically add CPTs to the sitemap used by Google etc. Yoast (and presumably the other plugins) have an option to turn off the sitemap for specific post types. – FluffyKitten Sep 28 '17 at 14:26
  • Ah yup, you are correct. Had to disable it in the Yoast site map. That explains why it's never really happened until now. Is there a way to setup my CPT so Yoast doesn't enable it by default? – paper_robots Sep 28 '17 at 14:31
  • 1
    Glad that solved it. I'm going to add this info as an answer, as I think it might be helpful to other users - I only know this because it happened to me too :) – FluffyKitten Sep 28 '17 at 14:33
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"/"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.

  • 1
    Also, I tested and if you set a custom post type 'public' to false. It won't show up in yoast either. That way you won't have to turn it off in yoast every time. – paper_robots Sep 28 '17 at 14:44
  • @paper_robots Good info! I'll update my answer to include that too for other users. Edit - oh, wait... I thought setting it to public in register_post_type caused problems? Or did you mean set public to false somewhere else? – FluffyKitten Sep 28 '17 at 14:46
  • Ah actually setting public to false does cause some issues. So not a great fix, still doing some playing around. I'll update you if I figure something out. Thing is, this is a public plugin, so I don't want others to have this issue if possible. – paper_robots Sep 28 '17 at 14:50
  • @paper_robots Yes its probably the most widely used SEO plugin, so a comprehensive answer would be helpful. You can also add your own answer with your findings if you do sort out the "public=false" issue! – FluffyKitten Sep 28 '17 at 14:52
1

There is a way to hide a post type by default from Yoast. However your milage may vary depending on what you are doing with your post type. If you are using it on the front end directly then this won't work for you. In my case I was pulling the content via shortcodes.

So the 'public' argument when registering your post type enables/disables a few arguments at once. See the description here: https://codex.wordpress.org/Function_Reference/register_post_type

You can set these manually for a finer level of control. The argument I found that helped with my issue was publicly_queryable. By setting this to false, it disabled my custom post type from having front end pages. Which I didn't need. This hid the post type from Yoast. All the admin stuff continued to work, the post type was still functional in the ways I had needed it to be.

  • Ah yeah, "publicly_queryable" makes sense :) – FluffyKitten Sep 28 '17 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.