WordPress: Display screenshot of any website using shortcode

Do you often use screenshots of websites in your WordPress blog? You can make your blogging faster using a shortcode to add screenshot automatically. Copy-paste the following code snippet to the functions.php file of your WordPress theme. It will let you use the below mentioned shortcode to display a screenshot of any website. The default width and height of the screenshots are defined in pixels. You can change them to meet your requirements.

function wps_screenshot($atts, $content = null) {
        extract(shortcode_atts(array(
			"screenshot" => 'http://s.wordpress.com/mshots/v1/',
			"url" => 'http://',
			"alt" => 'Screenshot',
			"width" => '400',
			"height" => '300'
        ), $atts));
		return $screen = '<img src="' . $screenshot . '' . urlencode($url) . '?w=' . $width . '&h=' . $height . '" alt="' . $alt . '"/>';
}
add_shortcode("screenshot", "wps_screenshot");

Now to use this shortcode to add a thumbnail or screenshot of a website, you can use the following code with four attributes. You must add the URL parameter. If the rest are absent, defaults will be used. You can place this shortcode in your posts and pages.

[screenshot url="http://smartwebworker.com/"]
[screenshot url="http://smartwebworker.com/" alt="Free Web Design Resources"]
[screenshot url="http://smartwebworker.com/" alt="Free Web Design Resources" width="200" height="200"]

Premium WordPress Themes

Reliable Web Hosting

Smart Web Worker strongly recommends HostGator for your website/blog hosting. Sign up for web hosting at just $3.96/month. Use the coupon code "SMARTBLOGGER25" to get 25% discount on any hosting packages. Get an account with HostGator now!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>