Point Clear Media

Websites, Social Media, Online Marketing

Consultants in New Orleans, Fairhope

(251) 978-9910 | (504) 272-7664

How to Create a Video Sitemap with WordPress

Google VideosIf you have a lot of video content on the web, you will want to create a video sitemap to submit to Google and the other search engines.  Here is a step-by-step tutorial on how to create a video sitemap with WordPress.

Some of these steps might not be appropriate for your situation, but I will start at the point where you have your video files (e.g. .M4V, .MP4, .MOV, .FLV, etc…) on a publicly-accessible  web server somewhere and you have a fresh empty installation of WordPress also on a publicly-accessible  web server.

Publish Video Posts

  1. Create a new post category and give it the name “video.”
  2. Create a new post, and add a custom field called “video_url.” This can either be done on a post-by-post basis or you can use a plugin to automatically create custom field forms such as Custom Field Template.
  3. Give the custom field the full URL value of your first video URL (e.g. http://www.yoursite.com/videofolder/video.m4v).
  4. Give the post the title of the video.
  5. If you have a transcript or some written content about the video write it in the WYSIWYG editor. This will be seen by anyone who visits your site and will be good for SEO purposes.
  6. Write a short description of the video in the Excerpt text box. DO NOT add any code or any character other than alphanumeric characters.
  7. If your theme allows for a featured image, add the featured image in that section.  If not, you might choose to create another custom field and add the full URL value of the image location. It is recommended to make this image the same width and height of the video.
  8. Add relevant tags in the Post Tags section.
  9. Publish
  10. Repeat until all of your videos each have a unique post.

 Create Custom XML Page

  1. In your theme directory where your index.php and style.css files exist, create a new file and call it video-sitemap.php.
  2. Copy this code, and only this code, into video-sitemap.php:
<!-- create a Video Sitemap template -->
<?php
/*
Template Name: Video Sitemap
*/

<!-- create a variable called $posts -->
$posts = query_posts(array_merge(
array(
'cat' => 'video',
'posts_per_page' => 9999,
'meta_key' => 'video_url'

)
));
<!-- this is the namespace of the XML file and the top of the sitemap -->
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
';
?>
<!-- loop to get each video and thumbnail URL, one at a time -->
<?php foreach ($posts as $post) {
$hosted_file_name = get_post_meta($post->ID, 'video_url', true);
if ( has_post_thumbnail() ) {
$videothumbnail = get_the_post_thumbnail ($post->ID);
}
?>
<!-- get video URL as its own element node along with the video attributes - change the spaceholder URLs -->
<url>
<loc><?php echo the_permalink($post->ID); ?></loc>
<video:video>
<video:thumbnail_loc><?php echo $videothumbnail ?></video:thumbnail_loc>
<video:title><?php the_title(); ?></video:title>
<video:description><?php the_excerpt(); ?></video:description>
<video:content_loc><?php echo $hosted_file_name; ?></video:content_loc>
<video:player_loc>http://www.yourwebsite.com/file/path/yourflashplayer.swf</video:player_loc>
<video:publication_date><?php echo get_the_date('Y-m-d'); ?></video:publication_date>
<video:category>Here write the main content category of all of your videos</video:category>
<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<video:tag>' . $tag->name . '</video:tag> ';
}
}
?>
<!-- this should be set to "no" if these are not suitable for kids -->
<video:family_friendly>yes</video:family_friendly>
</video:video>
</url>

<?php } ?>

</urlset>
  1. Save this file and uploaded it to the server
  2. Return to your WordPress dashboard and create a new page. Give it the title “Video Sitemap” so that the URL is http://www.yoursite.com/video-sitemap/.
  3. You will find a “Page Template” dropdown box. Choose “Video Sitemap” (which was declared at the top of the XML file you just created).
  4. Publish

There should now be a video sitemap at http://www.yoursite.com/video-sitemap/. You can submit this URL to Google Webmaster Tools as a sitemap.

6 Comments

  1. Looks like a very good and straight forward solution in comparision to clunky and unnecessary plugin bloats. However, the xml file i have created does not appear in the page-template dropdown.
    Is it because it is not a php file ? Please shed some light.
    Cheers….

  2. Bunty

    There was a mistake in my instructions. Name the file that you put inside your theme video-sitemap.php, not video-sitemap.xml.

    I have corrected the mistake above. See if that works.

    Burke

  3. Hello burke,

    thank you, the solution worked perfectly. I really appreciate your quick feedback. There was a just a minor glitch though on line 25. the code $videothumbnail = get_post_thumbnail ($post->ID);, threw an error “call to undefined function”. However when replaced with the_post_thumbnail, it works perfectly. Any thoughts on that ?

    My major concern however is that google expects a sitemap with a .xml extension instead of an html page, any workaround to that?

    Other that that it works like charm. Thank you for taking your time for this tutorial. It is very unique and helpful.

    Cheers.

    Bunty.

  4. sorry..Just a quick correction, I replaced get_post_thumbnail with get_the_post_thumbnail and it worked as expected. However I am still clueless on how to render a .xml sitemap? Any help will be truly appreciated. Thanks.

  5. Perhaps you could rewrite the URL in .htaccess to display it as video-sitemap.xml instead of /video-sitemap/. I’m not exactly sure of the exact code, but perhaps it would be in the same way that WordPress creates permalinks.

  6. Thanks for the edit. I have replaced get_post_thumbnail with get_the_post_thumbnail above.

Leave a Comment

© 2013 Point Clear Media, LLC | This is a Mobile251.com Networked Website. | Google+