If 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.
<!-- 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_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>
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.
No comments
Leave a Comment