Get Notified Every Time GoogleBot Crawls Your WP Blog

This entry was posted on Thursday, October 27th, 2011 and is filed under apps, PHP.

In this post I will demonstrate how to use PHP to get notifications when Google Bot crawls your web page or WP Blog. This will help you with SEO.

Using WP Functions:

Here I will use get_bloginfo(); and get_the_title(); to get title of the page. This is important to know the webpage which has been just crawled by Googlebot.

<?php
if (is_home()) {
$title=get_bloginfo();
}
else
{
$title = get_the_title();
}
$title=$title.' Crawled by Googlebot Just Now';
$to = "seo@example.com";
$subject = "Googlebot";
$from = "site@example.com";
$headers = "From:" . $from;
if (strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false )
{
mail($to,$subject,$title,$headers);
}
?>

Copy this code to header.php in your wp-blog template.
If you want to get an alert for static webpage crawling, then use the following code.

<?php
$message='This Page Crawled by Googlebot Just Now';
$to = "seo@example.com";
$subject = "Googlebot";
$from = "site@example.com";
$headers = "From:" . $from;
if (strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false )
{
mail($to,$subject,$title,$headers);
}
?>

Testing:- Once you complete above steps, sign in in to your Google Webmaster tools Diagnostics > Fetch as Googlebot, enter the url with above tracking code and click fetch. You would get a mail saying that your page has been crawled by Google!

You Might Also Like

Filed Under: apps, PHP