Creating Simple oEmbed-Based WordPress Shortcodes


/ Published in: PHP
Save to your folder(s)

Say you wanted to create a shortcode like this: [youtube id="991WcoEPwb8"]

And instead of manually creating the HTML yourself, you wanted to use YouTube’s oEmbed provider to get the HTML. While that’s easy to do using WordPress’ existing functions (wp_oembed_get() for example), you must implement your own caching of the result as WordPress’ oEmbed class does not include any caching of it’s own.

However, WordPress comes with an [embed] shortcode that’s also secretly used for the shortcode-less embeds. A cool trick is to make that shortcode’s existing code (complete with caching) work for you! This post explains how to do it.

URL: http://www.viper007bond.com/2010/06/23/creating-simple-oembed-based-wordpress-shortcodes/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.