SermonAudio.com is a powerful media browser with tons of great content. It allows ministries to easily put their sermons online for the world to listen. SermonAudio handles everything from audio to video streaming across a huge range of platforms.
Adding sermons to WordPress is a fairly simple task given WordPress’ oEmbed API. Churches, bloggers, and ministries could easily take advantage of it and should. Sermons can be embedded as citations, as recommendations, or even just to keep the content in circulation.
For the sake of this how-to I’ll be showing you the easiest way to embed SermonAudio sermons. I won’t go into the advanced process of creating widgets and shortcodes. I’ll only show you how to make sermonaudio.com links embed audio sermons automatically.
WordPress’ oEmbed API
WordPress has had the oEmbed API since version 2.9. It has consistently been updated, and has added support for new default providers over time. Unfortunately SermonAudio is not on their list of default providers, but there’s hope! The API itself is extendable so you are free to add your own providers if they’re not natively supported.
Using The API
oEmbed is a simple way to allow URLs to display embeddable content automatically. If you were to paste a link to a YouTube video in your post, WordPress would automatically get everything needed to display the video on your site.
YouTube is only one example of a default provider, for a full list you can visit the WordPress codex.
Extend The API to Embed SermonAudio Sermons
Now lets try to achieve the same effect for SermonAudio content. In order for us to embed SermonAudio sermons we’re going to need to register SermonAudio as a provider, and then provide WordPress with link to SermonAudio’s sermon page.
We can register the provider by hooking into the init action in WordPress and adding the provider below.
add_action( 'init', function(){
wp_embed_register_handler();
});
Now that we have the provider registered we need to provide it with a url. This should be the url that we would like to be embeddable. On a side note, we will be working with some regex to parse the url. As an example we’ll use this sermon’s url.
You may have already noticed the query variable “SID” in the URL. The value it holds is the ID of the sermon, and is what we need to parse so that we can render our sermon.
$regex_url = '#http://(www\.)?sermonaudio\.com/sermoninfo.asp\?SID=([\d]+)#';
The first match in the regex is (www\.) which means that the www is optional. The second match in the regex is ([\d]+), this match requires that the value for SID is only an integer. Note, this will not work with a string.
Now let’s register SermonAudio as a valid provider, supply it with our regex string, and lastly give it a callback function to execute when regex finds a match.
add_action( 'init', function(){
$regex_url = '#http://(www\.)?sermonaudio\.com/sermoninfo.asp\?SID=([\d]+)#';
wp_embed_register_handler(
'sermonaudio',
$regex_url,
'wp_register_sermonaudio_embed',
true
);
});
Write The Callback Function
Now we need to add the proper callback wp_register_sermonaudio_embed to create the html needed for the embed.
function wp_register_sermonaudio_embed( $matches, $attr, $url, $rawattr ) {
}
Let’s try to understand what we’re working with. Our callback by default has 4 variables passed into it. The first variable is an array of regex matches, and for the sake of this tutorial we’ll only deal with that variable. Now let’s use the matches.
$embed = sprintf(
'<iframe style="min-width:250px;" width="100%%" height="150" frameborder="0" src="http://www.sermonaudio.com/saplayer/player_embed.asp?SID=%1$s"></iframe>',
esc_attr( $matches[2] )
);
We use a sprintf function to pass the data into our iframe. The iframe makes a call to SermonAudio’s web player with the provided sermon ID which is stored in the second key of the $matches array.
Lastly we’ll return the $embed variable as a filter.
function wp_register_sermonaudio_embed( $matches, $attr, $url, $rawattr )
{
$embed = sprintf(
'<iframe style="min-width:250px;" width="100%%" height="150" frameborder="0" src="http://www.sermonaudio.com/saplayer/player_embed.asp?SID=%1$s"></iframe>',
esc_attr( $matches[2] )
);
return apply_filters( 'wp_embed_sermonaudio', $embed, $matches, $attr, $url, $rawattr );
}
And that’s it! Now you can easily embed SermonAudio sermons by pasting SermonAudio links into your post, which would result in the following.
The Plugin
In case you were looking for a plugin to do this job, I went ahead and packaged all of this plus a little bit more into a plugin which will be on the WordPress Plugin Repo soon. You can grab it now on Github. The plugin allows for multiple urls to be embeddable and currently only supports audio embeds. You can download them below.
Conclusion
SermonAudio is a really great platform that you can utilize for your ministry. In fact, I’ve built a few tools that integrate with their services already. If you’re already using them to power your online ministry I would highly recommend working with their APIs to customize your user’s experience.