and like us on FB

While we’ve shied away from Pinterest in the past, we’re quickly catching up on lost time with a series of posts detailing various ways in which to interact with the platform. This article will show you how to include a Pinterest URL count with WordPress shortcode. If you’re not using WordPress there’s a naked PHP function that follows.

The Result

We’ll use a page from realsimple.com for our example because they always seem to attract a large number of pins. To render the count for a URL, use [pins url="http://www.realsimple.com/holidays-entertaining/holidays/christmas/how-to-hang-christmas-lights"]. The result: 2,223.

The WordPress Shortcode

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.

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.

Shortcode Attributes

url

The URL is the page you’re requesting a count from.

n

By default we’ll return the number in a number format . To silence the number format feature, use n="0" or hardcode it into the function.

cache

The cache is the number of seconds we’ll store the Pinterest count locally. Be default we’ll store it for 12 hours (3600 x12) before making another request to the Pinterest API.

The PHP Function

Used outside of WordPress, the following function can be used. Usage requires Simple Cache to avoid repeated requests to Pinterest.

Considerations

  • The JSON response doesn’t come from a Pinterest API designed to function as described above. Continued availability can’t be relied upon.

Download

Title: Display the number of Pinterest shares for a URL with WordPress shortcode.
Description: Display the number of Pinterest shares for a URL with WordPress shortcode.
Download: Shortcode (V0.2) | WP Plugin (V0.2) | PHP Code (V0.2)

Shortt URL for this post: http://shor.tt/1RXw