wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Display screenshot of any website using shortcode

wordpress snippet

Adding the first snippet to the functions.php of your wordpress theme will let you use the bellow shortcode to display a screenshot of any website.

snippet :  PHPcopy
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");
snippet :  SHORTCODEcopy
[screenshot url="http://wpsnipp.com" alt="wordpress code snippets for your blog" width="200" height="200"]

Did you like this post? If so please share it with your friends. Thanks!

  • http://wpsnipp.com Kevin Chard

    This may be true but if you preview your post before hand that should not be a big problem.

  • jamie

    The main downfall is not utilizing the featured image.

    • http://wpsnipp.com Kevin Chard

      Hi Jamie, You could do this with the featured image but would require you do create screenshots of every site. This way you only need to add the url of any site to get a screenshot.

  • Kevin McClellan

    I really like this snippit and just put it to use on my portfolio page. After the first page refresh the images seem to load just fine even on my other computer. So I guess they just have to go through that mshots once really. Pretty cool