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.
Note: This snippet is undergoing a rewrite. Provided code will fail. Check back soon.
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: N/A.
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.
n="0"or hardcode it into the function.
cacheis 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.
- The JSON response doesn't come from a Pinterest API designed to function as described above. Continued availability can't be relied upon.