Submit WordPress Post URLs to Google When Publishing – WordPress Tutorial

By | June 15, 2019

You can submit your wordpress post sitemap to google by Google Ping when published a post, which can increate your site crawl rate.

Google Ping Service is:

http://www.google.com/ping?sitemap=URL/of/file

How to submit your sitemap to google by google ping in wordpress?

Here is an example:

function submit_to_google(){
	$sitemap_url = 'https://www.tutorialexample.com/post-sitemap.xml';
	$ping_url = "http://www.google.com/ping?sitemap=".esc_url($sitemap);
	$response = wp_remote_get($ping_url);
	if ( is_wp_error( $response ) ) {
	        $error_message = $response->get_error_message();
            echo "Something went wrong: $error_message";
			 die();
	     } else {
	        print_r($response);
	     }
}
function submit_urls($ID, $post){
	submit_to_google();
}
add_action('publish_post', 'submit_urls', 10, 2 );

Then wordpress will notify google once you have published a post.

Leave a Reply