RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Website Snapshots with WordPress Shortcode

Website Snapshots with WordPress Shortcode

We originally wrote this code in 2010 with the expectation that WordPress would cease proving their screenshot API to the public. In the typical open spirit of WordPress, however, WP has stated that usage is fine as long as there's no expectation it'll last forever (we're sure that WP never intended for their service to be used indiscriminately by the online world). The feature was originally used to display screenshots of Commercial Themes . It's since made its way into your administration dashboard to associate URLs with website snapshots.

The following functions make use of the WordPress snapshot API and renders a screenshot on any post or page.

The Result

The shortcode of [snap url="http://www.flight.org/" alt="Flight" width="530" height="280"] will return the following image:

Flight

If the image isn't immediately available you'll see a preview image. The API appears to return an image with a maximum resolution of 1280 x 960 pixels.

The Code

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

1
<?php 
2
/*
3
 Website Snapshots with WordPress Shortcode
4
 http://www.beliefmedia.com/website-snapshots
5
*/
6
 
7
function beliefmedia_wp_snapshot($atts, $content = null) {
8
 
9
  $atts = shortcode_atts(array(
10
   "snap" => 'http://s.wordpress.com/mshots/v1',
11
   "url" => 'http://www.flight.org/',
12
   "alt" => false,
13
   "width" => '400',
14
   "height" => '300',
15
   "align" => 'center',
16
  ), $atts);
17
 
18
  /* If no alt text, we'll display the URL as alt text */
19
  if ($atts['alt'] === false) $atts['alt'] = $atts['url'];
20
 
21
 return '<div style="text-align:' . $atts['align'] . '"><img alt="' . $atts['alt'] . '" src="' . $atts['snap'] . '/' . urlencode($atts['url']) . '?w=' . $atts['width'] . '&h=' . $atts['height'] . '"></div>';
22
}
23
add_shortcode("snap", "beliefmedia_wp_snapshot");

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

You can define the website URL (url), alt text (alt), width (width), height (height), and image alignment (align) by way of shortcode attributes.

The first time you call the website it will take some time to render (it seems to cache on WordPress for an unknown period after that). I suggest you preview the post first and let the screenshot render before you publish your post to the world.

PHP Function

Using the function outside of WordPress seems a little unethical and I wouldn't recommend it. However, for the sake of completeness, the following PHP function will return a snapshot.

1
<?php 
2
/*
3
 Website Snapshots with WordPress Shortcode
4
 http://www.beliefmedia.com/website-snapshots
5
*/
6
 
7
function beliefmedia_wp_snapshot($url, $args = '') {
8
 
9
  $atts = array(
10
   "snap" => 'http://s.wordpress.com/mshots/v1',
11
   "url" => 'http://www.flight.org/',
12
   "alt" => false,
13
   "width" => '400',
14
   "height" => '300',
15
   "align" => 'center',
16
  );
17
 
18
  /* If no alt text, we'll display the URL as alt text */
19
  if ($atts['alt'] === false) $atts['alt'] = $atts['url'];
20
 
21
  /* Merge $args with $atts */
22
  $atts = (empty($args)) ? $atts : array_merge($atts, $args);
23
 
24
 return '<div style="text-align:' . $atts['align'] . '"><img alt="' . $atts['alt'] . '" src="' . $atts['snap'] . '/' . urlencode($atts['url']) . '?w=' . $atts['width'] . '&h=' . $atts['height'] . '"></div>';
25
}
26
 
27
/* Usage */
28
$url = 'http://www.flight.org/';
29
30
 
31
/* With arguments */
32
$args = array('width' => 800, 'height' => 600);
33
echo beliefmedia_wp_snapshot($url, $args);

Considerations

  • Given the nature of the source, respect the limits of your use. Don't expect any longevity from the service.
  • We have our own screenshot tool at Screenshotz . We'll soon be migrating all the features of that site into BeliefMedia and retiring the old platform.

Download


Title: Website Snapshots with WordPress Shortcode (WP Plugin)
Description: Shortcode makes use of the WordPress snapshot API and renders a website screenshot of any page or post.
  Download • Version 0.2, 1.4K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (589.0B)    PHP Code & Snippets, (658.0B)    

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment