Soundcloud oEmbed Support in WordPress

Soundcloud oEmbed Support in WordPress
It’s come from another post format I made in my tumblog theme. I’ve add a custom meta box in post editor to easily deal with the post format. Firstly, there’s a text input for audio URL and a textarea for SoundCloud embed code. I thought that’s not an effective way to solve this problem. I want just a text input for both audio URL or SoundCloud URL.

I looking for another way more effective and found built-in WordPress function, wp_oembed_get(). But I realized that the built-in library in WordPress doesn’t support SoundCloud oEmbed yet. Here the function wp_oembed_add_provider() works.

// Register oEmbed support for Soundcloud
wp_oembed_add_provider( 'http://soundcloud.com/*', 'http://soundcloud.com/oembed' );

The first argument, http://soundcloud.com/* is the URL structure that this (SoundCloud) oEmbed provider supports. The second, http://soundcloud.com/oembed is the base URL of the oEmbed provider. Actually there’s third argument, regex, but we doesn’t need it this time.

Here is the example of post custom meta data:

// Get the URL from custom field
$audio = get_post_meta($post->ID, 'daoon_audio', true);

// Echo the embedded sound
if ($audio)
    echo wp_oembed_get($audio);

And lastly, we just paste the SoundCloud track URL to the meta box and it automatically embedded. One thing I didn’t find the way is how we add a parameter to the embedded URL without entering it directly in the box. There’s an array argument after the URL at wp_oembed_get(), but I tried and it doesn’t work. Anyone knows, please leave at comment, thanks.

Useful Links

  1. WordPress Embeds
  2. Function Reference: wp oembed get()
  3. Function Reference: wp oembed add provider()
  4. Function Reference: wp_embed_register_handler(), registering non-oEmbed support

9 thoughts on “Soundcloud oEmbed Support in WordPress

    • As I know, you just need to paste the video URL and WordPress do the rest for you. In case its not, check media settings on your dashboard which state enable auto embeds.

  1. naturally like your web site however you need to take a look at the spelling on quite a few of your
    posts. Many of them are rife with spelling issues and I to
    find it very troublesome to inform the truth nevertheless I’ll certainly come back again.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>