Soundcloud Count

Insert Live SoundCloud Play Counts, Download Counts, Comment Counts, and Like Counts in WordPress with Shortcode (without the API)

A couple of weeks ago 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. Use of the API isn’t required.

The Result

To demonstrate the code we’ll mine the details of a cheesy Australian Bachelorette podcast from The Daily Telegraph (Australia). By default we’ll render the play count, so [soundclouds url="https://soundcloud.com/daily-telegraph/the-bachelorette-model-david-bites-the-dust-in-show-two"] will return the value of 11,210 (bolding is mine). To return the number of downloads, we’ll add the type attribute as follows: [soundclouds url="https://soundcloud.com/daily-telegraph/the-bachelorette-model-david-bites-the-dust-in-show-two" type="downloads"], and the shortcode will return the value of 36. At the time of writing there aren’t any comments or likes (I wonder why?)… but if they were to be returned you should use the type attribute as follows: type="likes", or type="comments".

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.

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 destination page for a single SoundCloud audio player.

type

The type determines what data is returned; count, downloads, comments, or likes. If nothing is specified it defaults to count.

n

By default the value returned will be in a number format with grouped thousands. To turn this feature off, use n="0" in your shortcode or hardcode it into the shortcode function.

cache

The cache is the amount of time the data is stored locally. By default we cache data for 8 hours.

Considerations

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:

Download the Code

Download the shortcode function here .

Shortt URL for this post:

Leave a Reply

Your email address will not be published. Required fields are marked *