WordPress shortcode: Display a thumbnail of any website
0 Comments
Did you know that WordPress .com have a service called mShots, which allow you to get snapshots of any website? In today’s recipe, I’m going to show you how to create a shortcode in order to easily display a snapshot of a specific website.
The first step is to create the shortcode. To do so, simply paste the code below into your functions.php file.
function wpr_snap($atts, $content = null) { extract(shortcode_atts(array( "snap" => 'http://s.wordpress.com/mshots/v1/', "url" => 'http://www.catswhocode.com', "alt" => 'My image', "w" => '400', // width "h" => '300' // height ), $atts)); $img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>'; return $img; } add_shortcode("snap", "wpr_snap");
Once done, you can use the snap shortcode, as shown in the following example:
[snap url="http://www.landofcreativity.com" alt="My description" w="300" h="200"]