Google XML Sitemap for Videos - Version 2.0

Version Description

Download this release

Release Info

Developer labnol
Plugin Icon wp plugin Google XML Sitemap for Videos
Version 2.0
Comparing to
See all releases

Code changes from version 1.0.4 to 2.0

Files changed (4) hide show
  1. readme.txt +53 -53
  2. screenshot-1.png +0 -0
  3. screenshot-2.png +0 -0
  4. video-sitemap.php +145 -151
readme.txt CHANGED
@@ -1,53 +1,53 @@
1
- === Plugin Name ===
2
- Contributors: labnol
3
- Tags: youtube, xml sitemaps, google sitemaps, bing, videos, seo, search engines, sitemap
4
- Requires at least: 2.9.2
5
- Tested up to: 3.0
6
- Stable tag: 1.0.4
7
-
8
- This plugin will help WordPress publishers generate Google XML Sitemaps for YouTube videos.
9
-
10
- == Description ==
11
-
12
- Sitemaps are a way to tell Google, Bing and other search engines about web pages, images and video content on your site that they may otherwise not discover.
13
-
14
- The Video Sitemap plugin will generate an XML Sitemap for your WordPress blog using all YouTube videos that you may have embedded in your blog posts.
15
-
16
- Your Video Sitemap will includes web pages which embed videos from YouTube or which links to videos on YouTube. If a YouTube video that you have in your blog has been removed from YouTube, the record in the Sitemap file will be ignored by Googlebot.
17
-
18
- **Related links:**
19
-
20
- You can follow [Digital Inspiration](http://www.labnol.org/ "Technology Blog") on [Twitter](http://twitter.com/labnol) and [Facebook](http://www.facebook.com/digital.inspiration).
21
-
22
- == Installation ==
23
-
24
- Here's how you can install the plugin:
25
-
26
- 1. Upload the plugins folder to the /wp-content/plugins/ directory.
27
- 1. Activate the plugin through the 'Plugins' menu in WordPress
28
- 1. Expand the Tools menu from WordPress dashboard sidebar and select "Video Sitemap."
29
- 1. Click the "Generate Sitemap" button to create your XML Sitemap for videos.
30
- 1. Once you have created your Sitemap, you can submit it to Google using Webmaster Tools.
31
-
32
- == Frequently Asked Questions ==
33
-
34
- = How can I submit my video sitemap to Google? =
35
-
36
- Once you have created your Sitemap, you can submit it to Google using Webmaster Tools. Google don't guarantee that all videos included in a Sitemap will appear in our search results, or that we will use all the video information included in your Sitemap.
37
-
38
- = Should I check the "include video duration" option when generating the sitemap? =
39
-
40
- If you have a *small number of videos* on your website, you may check this option. Please not that the plugin will make one call per video to the YouTube API to determine the duration of the clip. It uses CURL to interact with the YouTube API.
41
-
42
- = Where's the sitemap file stored? =
43
-
44
- You can find the video-sitemap.xml file in your blog's root folder.
45
-
46
- = Can I block search engines from indexing pages that are in the XML Sitemap file? =
47
-
48
- The Sitemaps protocol enables you to let search engines know what content you would like indexed. To tell search engines the content you don't want indexed, use a robots.txt file or add a robots meta tag to the web page that you would like to block.
49
-
50
- == Screenshots ==
51
-
52
- 1. Click the button to generate your video sitemap.
53
- 2. This is how the XML sitemap should look like in your web browser.
1
+ === Plugin Name ===
2
+ Contributors: labnol
3
+ Tags: youtube, xml sitemaps, google sitemaps, bing, videos, seo, search engines, sitemap
4
+ Requires at least: 2.9.2
5
+ Tested up to: 3.0
6
+ Stable tag: 2.0
7
+
8
+ This plugin will help you generate Google Video Sitemaps (XML) for your WordPress blog.
9
+
10
+ == Description ==
11
+
12
+ Sitemaps are a way to tell Google, Bing and other search engines about web pages, images and video content on your site that they may otherwise not discover.
13
+
14
+ The Video Sitemap plugin will generate an XML Sitemap for your WordPress blog using all YouTube videos that you may have embedded in your blog posts.
15
+
16
+ Your Video Sitemap will includes web pages which embed videos from YouTube or which links to videos on YouTube. If a YouTube video that you have in your blog has been removed from YouTube, the record in the Sitemap file will be ignored by Googlebot.
17
+
18
+ **Related links:**
19
+
20
+ You can follow [Digital Inspiration](http://www.labnol.org/ "Technology Blog") on [Twitter](http://twitter.com/labnol) and [Facebook](http://www.facebook.com/digital.inspiration).
21
+
22
+ == Installation ==
23
+
24
+ Here's how you can install the plugin:
25
+
26
+ 1. Upload the plugins folder to the /wp-content/plugins/ directory.
27
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
28
+ 1. Expand the Tools menu from WordPress dashboard sidebar and select "Video Sitemap."
29
+ 1. Click the "Generate Sitemap" button to create your XML Sitemap for videos.
30
+ 1. Once you have created your Sitemap, you can submit it to Google using Webmaster Tools.
31
+
32
+ == Frequently Asked Questions ==
33
+
34
+ = How can I submit my video sitemap to Google? =
35
+
36
+ Once you have created your Sitemap, you can submit it to Google using Webmaster Tools. Google don't guarantee that all videos included in a Sitemap will appear in our search results, or that we will use all the video information included in your Sitemap.
37
+
38
+ = Should I check the "include video duration" option when generating the sitemap? =
39
+
40
+ If you have a *small number of videos* on your website, you may check this option. Please not that the plugin will make one call per video to the YouTube API to determine the duration of the clip. It uses CURL to interact with the YouTube API.
41
+
42
+ = Where's the sitemap file stored? =
43
+
44
+ You can find the video-sitemap.xml file in your blog's root folder.
45
+
46
+ = Can I block search engines from indexing pages that are in the XML Sitemap file? =
47
+
48
+ The Sitemaps protocol enables you to let search engines know what content you would like indexed. To tell search engines the content you don't want indexed, use a robots.txt file or add a robots meta tag to the web page that you would like to block.
49
+
50
+ == Screenshots ==
51
+
52
+ 1. Click the button to generate your video sitemap.
53
+ 2. This is how the XML sitemap should look like in your web browser.
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
video-sitemap.php CHANGED
@@ -1,151 +1,145 @@
1
- <?php
2
- /*
3
- Plugin Name: Google XML Sitemap for Videos
4
- Plugin URI: http://www.labnol.org/software/xml-video-sitemaps-for-google/14085/
5
- Description: This plugin will generate a XML Video Sitemap for your WordPress blog. Visit the <a href="tools.php?page=video-sitemap-generate-page">settings page</a> to create your video sitemap.
6
- Author: Amit Agarwal
7
- Version: 1.0.1
8
- Author URI: http://www.labnol.org/
9
- */
10
-
11
-
12
- add_action ('admin_menu', 'video_sitemap_generate_page');
13
-
14
- function video_sitemap_generate_page () {
15
- if (function_exists ('add_submenu_page'))
16
- add_submenu_page ('tools.php', __('Video Sitemap'), __('Video Sitemap'),
17
- 'manage_options', 'video-sitemap-generate-page', 'video_sitemap_generate');
18
- }
19
-
20
- function video_sitemap_generate () {
21
-
22
- if ($_POST ['submit']) {
23
- video_sitemap_loop ();
24
- ?>
25
-
26
- <div class="wrap">
27
- <div style="float:right; margin:10px">
28
- <iframe src="http://www.facebook.com/plugins/likebox.php?id=5791561181&amp;width=250&amp;height=260&amp;connections=8&amp;stream=false&amp;header=false" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:250px; height:260px"></iframe>
29
- </div>
30
- <h2>XML Sitemap for Videos</h2>
31
- <?php $sitemapurl = get_bloginfo('url') . "/video-sitemap.xml"; ?>
32
- <p>The XML Sitemap was generated successfully. Please open the <a target="_blank" href="<?php echo $sitemapurl; ?>">Sitemap file</a> in your favorite web browser to confirm that there are no errors.</p>
33
- <p>You can submit your Video XML Sitemap through <a href="http://www.google.com/webmasters/tools/" target="_blank">Webmaster Tools</a> or you can directly <a target="_blank" href="http://www.google.com/webmasters/sitemaps/ping?sitemap=<?php echo $sitemapurl; ?>">ping Google</a>.</p>
34
- <h3>Suggestions?</h3>
35
- <p>Please email your suggestions to Amit Agarwal at amit@labnol.org. You can also connect with <a href="http://www.labnol.org/" target="_blank">Digital Inspiration</a> on <a href="http://twitter.com/labnol" target="_blank">Twitter</a> and <a href="http://www.facebook.com/digital.inspiration" target="_blank">Facebook</a>. </p>
36
-
37
- <?php } else { ?>
38
-
39
- <div class="wrap">
40
- <h2>XML Sitemap for Videos</h2>
41
- <p>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. </p>
42
-
43
- <h3>Create Video Sitemap</h3>
44
-
45
- <form id="options_form" method="post" action="">
46
- <input type="checkbox" id="sboption" name="time" value="1" />
47
- <label for="sboption">Include video length? (Not recommended for sites will large number of videos)</label>
48
- <div class="submit">
49
- <input type="submit" name="submit" id="sb_submit" value="Generate Video Sitemap" />
50
- </div>
51
- </form>
52
- <p>You can click the button above to generate a Video Sitemap for your website. Once you have created your Sitemap, you should submit it to Google using Webmaster Tools. </p>
53
-
54
- <h3>Suggestions?</h3>
55
- <p>Please email your suggestions to Amit Agarwal at amit@labnol.org.</p><p> You can also connect with <a href="http://www.labnol.org/" target="_blank">Digital Inspiration</a> on <a href="http://twitter.com/labnol" target="_blank">Twitter</a> and <a href="http://www.facebook.com/digital.inspiration" target="_blank">Facebook</a>. </p>
56
- </div>
57
-
58
- <?php }
59
- }
60
-
61
- function video_sitemap_loop () {
62
- global $wpdb;
63
-
64
- $posts = $wpdb->get_results ("SELECT id, post_title, post_content, post_date_gmt, guid, post_excerpt
65
- FROM $wpdb->posts
66
- WHERE post_status = 'publish'
67
- AND post_type = 'post'
68
- AND post_content LIKE '%youtube.com%'
69
- ORDER BY post_date DESC");
70
-
71
- if (empty ($posts)) {
72
- return false;
73
-
74
- } else {
75
-
76
- $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
77
- $xml .= '<?xml-stylesheet type="text/xsl" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/xml-sitemaps-for-videos/video-sitemap.xsl"?>' . "\n" ;
78
- $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">' . "\n";
79
-
80
- foreach ($posts as $post) {
81
- if (preg_match_all ("(<embed[^>]*src=['\"]http:\/\/www.youtube.com\/v\/([a-zA-Z0-9\-_]*)|youtube.com\/watch\?v=([a-zA-Z0-9\-_]*))",
82
- $post->post_content, $matches, PREG_SET_ORDER)) {
83
-
84
- $excerpt = ($post->post_excerpt != "") ? $post->post_excerpt : $post->post_title ;
85
- $permalink = get_permalink($post->id);
86
-
87
- foreach ($matches as $match) {
88
- $id = $match [1];
89
- if ($id == '') $id = $match [2];
90
- if ($id == '') $id = $match [3];
91
-
92
- $xml .= "\n <url>\n";
93
- $xml .= " <loc>$permalink</loc>\n";
94
- $xml .= " <video:video>\n";
95
- $xml .= " <video:player_loc allow_embed=\"yes\" autoplay=\"autoplay=1\">http://www.youtube.com/v/$id</video:player_loc>\n";
96
- $xml .= " <video:thumbnail_loc>http://i.ytimg.com/vi/$id/2.jpg</video:thumbnail_loc>\n";
97
- $xml .= " <video:title>" . htmlspecialchars($post->post_title) . "</video:title>\n";
98
- $xml .= " <video:description>" . htmlspecialchars($excerpt) . "</video:description>\n";
99
-
100
- if ($_POST['time'] == 1) {
101
- $duration = youtube_duration ($id);
102
- if ($duration != 0)
103
- $xml .= " <video:duration>".youtube_duration ($id)."</video:duration>\n";
104
- }
105
-
106
- $xml .= " <video:publication_date>".date (DATE_W3C, strtotime ($post->post_date_gmt))."</video:publication_date>\n";
107
-
108
- $posttags = get_the_tags($post->id); if ($posttags) {
109
- foreach ($posttags as $tag) {
110
- $xml .= " <video:tag>$tag->name</video:tag>\n";
111
- }
112
- }
113
-
114
- $postcats = get_the_category($post->id); if ($postcats) {
115
- foreach ($postcats as $category) {
116
- $xml .= " <video:category>$category->name</video:category>\n";
117
- }
118
- }
119
-
120
- $xml .= " </video:video>\n </url>";
121
- }
122
- }
123
- }
124
-
125
- $xml .= "\n</urlset>";
126
- }
127
-
128
- $video_sitemap_url = $_SERVER["DOCUMENT_ROOT"] . '/video-sitemap.xml';
129
- file_put_contents ($video_sitemap_url, $xml);
130
-
131
- }
132
-
133
- # given a video id, get the duration.
134
- # might give this a delay to avoid running into issues with YouTube.
135
- function youtube_duration ($id) {
136
- try {
137
- $ch = curl_init ();
138
- curl_setopt ($ch, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos/$id");
139
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
140
- $data = curl_exec ($ch);
141
- curl_close ($ch);
142
-
143
- preg_match ("/duration=['\"]([0-9]*)['\"]/", $data, $match);
144
- return $match [1];
145
-
146
- } catch (Exception $e) {
147
- # returning 0 if the YouTube API fails for some reason.
148
- return '0';
149
- }
150
- }
151
- ?>
1
+ <?php
2
+ /*
3
+ Plugin Name: Google XML Sitemap for Videos
4
+ Plugin URI: http://www.labnol.org/software/xml-video-sitemaps-for-google/14085/
5
+ Description: This plugin will generate a XML Video Sitemap for your WordPress blog. Open the <a href="tools.php?page=video-sitemap-generate-page">settings page</a> to create your video sitemap.
6
+ Author: Amit Agarwal
7
+ Version: 2.0
8
+ Author URI: http://www.labnol.org/
9
+ */
10
+
11
+ add_action ('admin_menu', 'video_sitemap_generate_page');
12
+
13
+ function video_sitemap_generate_page () {
14
+ if (function_exists ('add_submenu_page'))
15
+ add_submenu_page ('tools.php', __('Video Sitemap'), __('Video Sitemap'),
16
+ 'manage_options', 'video-sitemap-generate-page', 'video_sitemap_generate');
17
+ }
18
+
19
+ function video_sitemap_generate () {
20
+
21
+ if ($_POST ['submit']) {
22
+ video_sitemap_loop ();
23
+ ?>
24
+
25
+ <div class="wrap">
26
+ <div style="float:right; margin:10px">
27
+ <iframe src="http://www.facebook.com/plugins/likebox.php?id=5791561181&amp;width=250&amp;height=260&amp;connections=8&amp;stream=false&amp;header=false" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:250px; height:260px"></iframe>
28
+ </div>
29
+ <h2>XML Sitemap for Videos</h2>
30
+ <?php $sitemapurl = get_bloginfo('url') . "/video-sitemap.xml"; ?>
31
+ <p>The XML Sitemap was generated successfully. Please open the <a target="_blank" href="<?php echo $sitemapurl; ?>">Sitemap file</a> in your favorite web browser to confirm that there are no errors.</p>
32
+ <p>You can submit your Video XML Sitemap through <a href="http://www.google.com/webmasters/tools/" target="_blank">Webmaster Tools</a> or you can directly <a target="_blank" href="http://www.google.com/webmasters/sitemaps/ping?sitemap=<?php echo $sitemapurl; ?>">ping Google</a>.</p>
33
+ <h3>Suggestions?</h3>
34
+ <p>Please email your suggestions to Amit Agarwal at amit@labnol.org. You can also connect with <a href="http://www.labnol.org/" target="_blank">Digital Inspiration</a> on <a href="http://twitter.com/labnol" target="_blank">Twitter</a> and <a href="http://www.facebook.com/digital.inspiration" target="_blank">Facebook</a>. </p>
35
+ <?php } else { ?>
36
+ <div class="wrap">
37
+ <h2>XML Sitemap for Videos</h2>
38
+ <p>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. </p>
39
+ <h3>Create Video Sitemap</h3>
40
+ <form id="options_form" method="post" action="">
41
+ <input type="checkbox" id="sboption" name="time" value="1" />
42
+ <label for="sboption">Include video length? (Not recommended for sites will large number of videos)</label>
43
+ <div class="submit">
44
+ <input type="submit" name="submit" id="sb_submit" value="Generate Video Sitemap" />
45
+ </div>
46
+ </form>
47
+ <p>You can click the button above to generate a Video Sitemap for your website. Once you have created your Sitemap, you should submit it to Google using Webmaster Tools. </p>
48
+ <h3>Suggestions?</h3>
49
+ <p>Please email your suggestions to Amit Agarwal at amit@labnol.org.</p>
50
+ <p> You can also connect with <a href="http://www.labnol.org/" target="_blank">Digital Inspiration</a> on <a href="http://twitter.com/labnol" target="_blank">Twitter</a> and <a href="http://www.facebook.com/digital.inspiration" target="_blank">Facebook</a>. </p>
51
+ </div>
52
+ <?php }
53
+ }
54
+
55
+ function video_sitemap_loop () {
56
+ global $wpdb;
57
+
58
+ $posts = $wpdb->get_results ("SELECT id, post_title, post_content, post_date_gmt, guid, post_excerpt
59
+ FROM $wpdb->posts
60
+ WHERE post_status = 'publish'
61
+ AND post_type = 'post'
62
+ AND post_content LIKE '%youtube.com%'
63
+ ORDER BY post_date DESC");
64
+
65
+ if (empty ($posts)) {
66
+ return false;
67
+
68
+ } else {
69
+
70
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
71
+ $xml .= '<?xml-stylesheet type="text/xsl" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/xml-sitemaps-for-videos/video-sitemap.xsl"?>' . "\n" ;
72
+ $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">' . "\n";
73
+
74
+ foreach ($posts as $post) {
75
+ if (preg_match_all ("(<embed[^>]*src=['\"]http:\/\/www.youtube.com\/v\/([a-zA-Z0-9\-_]*)|youtube.com\/watch\?v=([a-zA-Z0-9\-_]*))",
76
+ $post->post_content, $matches, PREG_SET_ORDER)) {
77
+
78
+ $excerpt = ($post->post_excerpt != "") ? $post->post_excerpt : $post->post_title ;
79
+ $permalink = get_permalink($post->id);
80
+
81
+ foreach ($matches as $match) {
82
+ $id = $match [1];
83
+ if ($id == '') $id = $match [2];
84
+ if ($id == '') $id = $match [3];
85
+
86
+ $xml .= "\n <url>\n";
87
+ $xml .= " <loc>$permalink</loc>\n";
88
+ $xml .= " <video:video>\n";
89
+ $xml .= " <video:player_loc allow_embed=\"yes\" autoplay=\"autoplay=1\">http://www.youtube.com/v/$id</video:player_loc>\n";
90
+ $xml .= " <video:thumbnail_loc>http://i.ytimg.com/vi/$id/2.jpg</video:thumbnail_loc>\n";
91
+ $xml .= " <video:title>" . htmlspecialchars($post->post_title) . "</video:title>\n";
92
+ $xml .= " <video:description>" . htmlspecialchars($excerpt) . "</video:description>\n";
93
+
94
+ if ($_POST['time'] == 1) {
95
+ $duration = youtube_duration ($id);
96
+ if ($duration != 0)
97
+ $xml .= " <video:duration>".youtube_duration ($id)."</video:duration>\n";
98
+ }
99
+
100
+ $xml .= " <video:publication_date>".date (DATE_W3C, strtotime ($post->post_date_gmt))."</video:publication_date>\n";
101
+
102
+ $posttags = get_the_tags($post->id); if ($posttags) {
103
+ foreach ($posttags as $tag) {
104
+ $xml .= " <video:tag>$tag->name</video:tag>\n";
105
+ }
106
+ }
107
+
108
+ $postcats = get_the_category($post->id); if ($postcats) {
109
+ foreach ($postcats as $category) {
110
+ $xml .= " <video:category>$category->name</video:category>\n";
111
+ }
112
+ }
113
+
114
+ $xml .= " </video:video>\n </url>";
115
+ }
116
+ }
117
+ }
118
+
119
+ $xml .= "\n</urlset>";
120
+ }
121
+
122
+ $video_sitemap_url = $_SERVER["DOCUMENT_ROOT"] . '/video-sitemap.xml';
123
+ file_put_contents ($video_sitemap_url, $xml);
124
+
125
+ }
126
+
127
+ # given a video id, get the duration.
128
+ # might give this a delay to avoid running into issues with YouTube.
129
+ function youtube_duration ($id) {
130
+ try {
131
+ $ch = curl_init ();
132
+ curl_setopt ($ch, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos/$id");
133
+ curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
134
+ $data = curl_exec ($ch);
135
+ curl_close ($ch);
136
+
137
+ preg_match ("/duration=['\"]([0-9]*)['\"]/", $data, $match);
138
+ return $match [1];
139
+
140
+ } catch (Exception $e) {
141
+ # returning 0 if the YouTube API fails for some reason.
142
+ return '0';
143
+ }
144
+ }
145
+ ?>