Power User Tip: Custom Post Type Feeds & Google

Not many people realize the power that WordPress gives them by making feeds for everything on the site. If you register a custom post type it gets a feed by default, so for my new WordPress Plugin Review section, which is built on a custom post type for plugin reviews, there’s a custom feed here:

http://yoast.com/wp-plugin-review/feed/

That feed is actually a valid “sitemap” for Google Webmaster Tools as well, so you can just submit it there, as you can see here:

Custom Post Type feeds in Google Webmaster Tools

Custom Post Type feeds in Google Webmaster Tools

If you submit them there, Google will regularly poll them which will make it easier for you to get your custom post types indexed!

If you want to add your custom post type feed to the head section of your page, use the following code, of course adapting it for your own post type:

function yst_add_feed() {
	if ( is_post_type_archive( array('plugin_review') ) 
		|| is_singular( 'plugin_review' ) ) 
	{
		$feed = get_post_type_archive_feed_link( 'plugin_review' );
		echo '<link rel="alternate" type="application/rss+xml" 
			title="Plugin Reviews by Yoast RSS Feed" 
			href="'.$feed.'" />';
	}
}
add_action( 'wp_head', 'yst_add_feed' );

Tags:


Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

33 Responses

  1. Lew AyotteBy Lew Ayotte on 13 April, 2011

    add_feed() is already a defined function in WP core… /wp-includes/rewrite.php

    Probably should use a different function name.

    Also, it looks like you forgot to add an action hook to call your new function :).

    Lew

    • Joost de ValkBy Joost de Valk on 13 April, 2011

      hehe ugh this is actually copied directly from my plugin review plugin’s class :) will change :)

    • Joost de ValkBy Joost de Valk on 13 April, 2011

      fixed :)

  2. Michael FieldsBy Michael Fields on 13 April, 2011

    Wow, I’m actually surprised that WordPress does do this automatically for public post types. Thanks for sharing the fix! FWIW, the conditional could be simplified by using is_singular( ‘plugin_review’ ).

    • Joost de ValkBy Joost de Valk on 13 April, 2011

      fair enough, updated it to reflect that :)

  3. Peter WilsonBy Peter Wilson on 14 April, 2011

    Do you know the name of the bot Google use to crawl sitemaps submitted in this manner?

    Like everyone else, I redirect everything but the Feedburner bot, it would be handy to add Google’s sitemap bot as an exception.

    Cheers,
    Peter

    • Joost de ValkBy Joost de Valk on 15 April, 2011

      I’ve actually hacked around that quite a bit, and am not redirecting all feeds to FeedBurner, as the often used plugin does…

  4. KristofBy Kristof on 14 April, 2011

    Great tip – thanks.

    Noticed you have a video_sitemap feed as well (Generated by Yoast’s WordPress SEO plugin) — have you released that module yet?

    • Joost de ValkBy Joost de Valk on 15 April, 2011

      No I haven’t, still coding away on it (it’s bloody hard to get right)

      • KristofBy Kristof on 15 April, 2011

        IMO – even you’re “not quite right” code is really good. I’m ready to beta test for you.

  5. RickBy Rick on 14 April, 2011

    For my website… I have Feature Video, Video, News-Gossip, and Premium Videos…these a basically main categories I always create new post for. Are you saying I should have a sitemap for each categorie… instead of using sitemap.xml.gz?

    • Joost de ValkBy Joost de Valk on 15 April, 2011

      But they’re categories, not post types right? You could still throw them all into Google Webmaster Tools, it’d actually give you a good view of how certain sections of your site are being indexed.

  6. Thomas ClausenBy Thomas Clausen on 14 April, 2011

    I like the idea of getting a feed of the custom post type, but they don’t get in the same RSS stream as the regular post right? As far as I recall last time I tried I couldn’t get that to work.

    • Joost de ValkBy Joost de Valk on 15 April, 2011

      I’ve actually just done it for my best practices custom post type, they now show up in my feed. This little snippet from @DeFries was quite helpful.

      • ChristopherBy Christopher on 18 April, 2011

        Sorry, what snippet from @DeFries was that?

    • NeelBy Neel on 1 May, 2011

      @thomas Clausen, Even i tried a lot but could not get it to work but still i love word press and its simply the best.

  7. Vayu RobinsBy Vayu Robins on 14 April, 2011

    This is a great tip, something I didn’t really know was possible.
    I am having trouble getting this to work though. If I use the do_action function call, it duplicates the wp_head stuff and places it above the DOCTYPE.
    I can’t seem to find a working solution for this.

    Thanks
    Vayu

    • Joost de ValkBy Joost de Valk on 15 April, 2011

      That’s actually because of a fault in that code, I’m sorry. Just changed it, it should be add_action, not do_action.

      • Vayu RobinsBy Vayu Robins on 15 April, 2011

        Thanks Joost. Yes, I figured that out later on. :-)

        What is required for WP to register an archive page for the CPT? When I test this:
        is_post_type_archive( array('portfolio') )
        it tells me that there isn’t any archive page. When I registered my CPT I even used:
        'has_archive' => true,

        Anyway, I know this might not be the right place for support, but I appreciate any tips on this. :-)

        Vayu

        • Joost de ValkBy Joost de Valk on 15 April, 2011

          This:

          is_post_type_archive( array('portfolio') )

          will only return true on the archive page for that post type, so on example.com/portfolio/, if portfolio is also the slug you used to register the post type.

          • Vayu RobinsBy Vayu Robins on 15 April, 2011

            Great, thanks!
            Vayu

  8. SanderBy Sander on 15 April, 2011

    This is a great tip! Never even thought about it, but used it right away on a new site I’m building using CPT..

    Thanks, Sander

  9. MusthafaBy Musthafa on 16 April, 2011

    Great Tip and thanks for sharing the information..

  10. Dries (Online Marketing - bSeen.be)By Dries (Online Marketing - bSeen.be) on 18 April, 2011

    You could do the same by using the multisite option WP, but that is a lot of extra work and maybe the hardest way to get things sorted out. Cool tip Joost. tnx!

  11. AlexBy Alex on 19 April, 2011

    Hi,

    Just wondering a little tangentially how one implements Yoast SEO for a custom post type? Some of my custom post types seem to work automatically with SEO, however, ones I have implemented myself show the Yoast SEO form, but nothing is saved when the custom post is saved. Just wondering what the problem might be.

    Thanks a lot for all your wonderful plugins by the way!

  12. ProDeBy ProDe on 19 April, 2011

    Hi, I like the idea to use the feed as a sitemap.
    Can this somehow work for images also.
    Thanks!

  13. ProDeBy ProDe on 19 April, 2011

    Hi, nice text. Thanks!

  14. Rhys WigginsBy Rhys Wiggins on 20 April, 2011

    This is awesome! I thought about trying this a while back, but thought I was nuts and it wouldn’t work.

    Thanks for the post, I will be putting it to good use!

  15. AjayBy Ajay on 21 April, 2011

    but what’s the benefit of having multiple feeds for the same data? or we can have different feeds for different data like video sitemap etc?

  16. ChandanaBy Chandana on 21 April, 2011

    Cool stuffs for WordPress SEO ,Feed is very important for SEO

  17. Sven Raphael SchneiderBy Sven Raphael Schneider on 23 April, 2011

    Very interesting indeed, thanks. Now, in your Google Webmaster Tools picture you have a type called images. Can wordpress also created a feed or sitemape for images only which I can then submit to Google Webmaster Tools? Thanks

Trackbacks