On Monday we provided the first of a few variants of shortcode that would render a SoundCloud audio player in your WordPress website. This article will provide code that'll periodically mine SoundCloud for a play count, download count, comment count, or like count. Because we're scraping the freely provided meta data, use of the API isn't required.
Note: Soundcloud have removed the necessary META data from their HTML page. After a number of years they've still not opened the API back up for public registrations. This reason alone is why we use Wistia and Omny.fm for podcasts. The code and method shown below is invalid - we'll update it if able in the future.
To demonstrate the code we'll mine the details from the NSFA National Film and Sound Archive . By default we'll render the play count, so
[soundclouds url="https://soundcloud.com/nfsaaustralia/sets/early-talkback-radio-in"] will return the value of
N/A. To return the number of downloads, we'll add the type attribute as follows:
[soundclouds url="https://soundcloud.com/nfsaaustralia/sets/early-talkback-radio-in" type="downloads"], and the shortcode will return the value of
Likes are returned as follows:
The Shortcode Function
Copy and paste the WordPress function into your theme's
functions.php file or, if you sensibly have one installed, your custom functions plugin.
urlis the destination page for a single SoundCloud audio player.
typedetermines what data is returned; count, downloads, comments, or likes. If nothing is specified it defaults to count.
n="0"in your shortcode or hardcode it into the shortcode function.
cacheis the amount of time the data is stored locally. By default we cache data for 8 hours.
- While we mine the destination page for data, results are stored locally in your own WordPress installation using the transient API. We cache the results for 8 hours by default but, if you're comfortable doing so, you can query the SoundCloud URL more often.
- As we've done in the past for Facebook, Twitter, and other counts, you might consider altering the code to return an image rather than text. For example, using the same URL as above, we can render the play count as follows:
- Since our method of obtaining data is achieved by scraping META data, it will cease to work if SoundCloud stop providing that information.
No longer available.