Adding Custom Post Types to Sitemap

The Google Sitemap Generator WordPress Plugin is the most widely used plugin to generate a sitemap for a wordpress site. However it doesn’t support custom types yet. Hence the Google Bot hasn’t been visiting my website as frequently coz the sitemap doesn’t have the posts I add on my custom microblog. So I modified the plugin to add support for all public non-built-in post types. Here’s the patch.

To apply the patch, go to the folder of the google sitemap generator plugin ROOTDIR/wp-content/plugins/google-sitemap-generator and execute the below command.

zcat sitemap.patch.gz | patch -p0

Do make sure you specify the correct path for sitemap.patch.gz.

If you want a more elegant solution, go here. I found it after I wrote the patch :(.

I’m adding it directly to the plugin code, hoping that the next release of the plugin would bring support for custom post types and I won’t have to worry about the patch being overwritten.

Redirect WordPress XMLRPC Clients to a Custom Post Type

Lets say you want to post from your Android or Iphone WordPress clients to a custom post type instead of the the defualt ‘post’ type. Paste the code below in your functions.php and you should be good to go 🙂

function redirect_xmlrpc_to_custom_post_type ($data, $postarr) {
    $p2_custom_post_type = 'custom_post_type'; //Change this to the custom post type you are using for your blog
    if (defined('XMLRPC_REQUEST') || defined('APP_REQUEST')) {
        $data['post_type'] = $p2_custom_post_type;
        return $data;
    }
    return $data;
}

add_filter('wp_insert_post_data', 'redirect_xmlrpc_to_custom_post_type', 99, 2);

Change $p2_custom_post_type = 'custom_post_type' to the custom post type you are using for your blog.

Now I can post from my Android Phone to my custom P2 micro-blog 🙂