XML Sitemap for Images
The XML Sitemap was generated successfully and you can ping Google to inform them about your updated sitemap.
This WordPress Plugin is written by Amit Agarwal of Digital Inspiration. For feedback or suggestions on improving this plugin, please send me an email at amit@labnol.org
XML Sitemap for Images
Sitemaps are a way to tell Google and other search engines about web pages, images and video content on your site that they may otherwise not discover.
Click the button above to generate a Image Sitemap for your website. Once you have created your Sitemap, you should submit it to Google using Webmaster Tools.
You may also want to create separate Video Sitemap and Mobile Sitemap for improving your site's visibility in Google.
This WordPress Plugin is written by Amit Agarwal of Digital Inspiration.
get_results ("SELECT id, post_parent, post_content, guid, post_type FROM $wpdb->posts wposts
WHERE ((wposts.post_type = 'post') and (wposts.post_status='publish'))
OR ((wposts.post_type = 'page') and (wposts.post_status='publish'))
OR ((wposts.post_type = 'attachment') and (wposts.post_status='inherit')
and ((wposts.post_mime_type = 'image/jpg') or (wposts.post_mime_type = 'image/gif')
or (wposts.post_mime_type = 'image/jpeg') or (wposts.post_mime_type = 'image/png')))
");
if (empty ($posts)) {
return false;
} else {
$xml = ''."\n";
$xml .= ''."\n";
$xml .= ''."\n";
$xml .= '
'."\n";
foreach($posts as $post) {
if($post->post_type == "attachment") {
if($post->post_parent != 0) {
$images[$post->post_parent][] = $post->guid;
}
}
else if(preg_match_all("/[\'\"](http:\/\/.[^\'\"]+\.(?:jpe?g|png|gif))[\'\"]/ui", $post->post_content, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
$images[$post->id][] = $match[1];
}
}
}
foreach($images as $k => $v) {
$permalink = get_permalink($k);
if ( ! empty ( $permalink ) ) {
$img = "".implode("", $v)."";
$xml .= "" . EscapeXMLEntities($permalink) . "" . $img . "";
}
}
$xml .= "\n";
}
$image_sitemap_url = $_SERVER["DOCUMENT_ROOT"].'/sitemap-image.xml';
if(IsImageSitemapWritable($_SERVER["DOCUMENT_ROOT"]) || IsImageSitemapWritable($image_sitemap_url)) {
if(file_put_contents($image_sitemap_url, $xml)) {
return true;
}
}
return false;
}
?>