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
// 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.