Using WordPress MShots

14 Dec 2010

Using WordPress MShots


With WordPress blog sites, you can either host your own via WordPress.org’s downloadable WP scripts, or host with WordPress.com. There’s usually not much of a difference between the two, although most of the time hosting your own site will give you more control over what happens behind the scenes. There are the occasional benefits of hosting with WordPress.com, like the use of M-Shots. M-Shots allow you to post a dynamic screenshot of any URL. Below is a script for a shortcode that will allow you to make use of the M-Shots on your self hosted WordPress sites.

Google Search Engine
<?php 
/* 
Plugin Name: Website Screenshot Shortcode Plugin 
URI: http://mikepayne.co/using-wordpress-m-shots 
Description: This snippet allows you to display an image of a website, using only a shortcode 
Version: 0.1 
Author: Mike Payne 
Author URI: http://mikepayne.co 
*/ 

function mp_mshots($atts, $content = null) { 
  extract(shortcode_atts(array( 
    "mshots" => 'http://s.wordpress.com/mshots/v1/',
    "url" => 'http://www.MikePayne.co',
    "alt" => 'Screenshot of MikePayne.co Website',
    "width" => '600',
    "height" => '350'
  ), $atts));
  $screenShot = '<img src="' . $mshots . urlencode($url) .'?w=' . $width . '&amp;h=' . $height . '" alt="' . $alt . '" />';
  return $screenShot;
}
add_shortcode("mpshots", "mp_mshots");
?>

Example
[ mpshots url="http://www.google.com" alt="Google Search Engine" width="475" height="200" ]

Leave a Reply

Your email address will not be published. Required fields are marked *