Home / functions.php / Display screenshot of any website using shortcode
  • How to Display screenshot of any website using shortcode


    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.

    ( click code to copy )

    wordpress snippet : PHP

    function wps_screenshot($atts, $content = null) {
    			"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");
    ( click code to copy )

    wordpress snippet : SHORTCODE

    [screenshot url="http://wpsnipp.com" alt="wordpress code snippets for your blog" width="200" height="200"]

    ( WordPress codex functions, hooks, in this snippet. )

    add_shortcode, shortcode_atts, wp,
  • 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.

    • 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

  • Facinet TourĂ©

    Any help on how to use this with a custom meta field that can be entered from front-end?