Convert youtube shortcode to includes some unique features for their users, such as the ability to embed videos using the [youtube] shortcode. Trouble arises when users migrate their blogs to a self-hosted solution using, since the format is incompatible.
In this post we will see how to create a shortcode that allows to display the [youtube] shortcode in our self-hosted blogs.

There are a bunch of approaches to this, and there are some rather complicated ones introducing preg_replace using regular expressions to obtain the URL but this is a very lightweight one that serves this purpose:

 * Convert youtube shortcode from format so it works in
 * @param array $atts Parameters
 * @return string Video embedded using iframe version
function startfunction_convert_youtube_sc( $atts ) {
    parse_str( parse_url( substr( $atts[0], 1 ), PHP_URL_QUERY ), $vars );
    return '[youtube]';
add_shortcode( 'youtube', 'startfunction_convert_youtube_sc' );

you can paste the code above in your functions.php file or similar.

2 thoughts on “Convert youtube shortcode to”

  1. That’s a certainly good advice. This is just if someone doesn’t want to add Jetpack but it’s a good advice nevertheless, there are a lot of good stuff in Jetpack.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s