I recently changed the theme on my website, and now all my videos, which were used on the posts with this format:

[youtube id="only the id here" width="600" height="350"]

are not understood, and inside the posts like this one.

The following message is shown where the video is supposed to be:

Please enter the url to a YouTube video.

How can I make it so I don't need to go into all the posts I have that has any video inside and edit in a way that WordPress will embed it?

  • Why not just use the built-in youtube embedding instead of using a custom shortcode? See Embeds.
    – t31os
    Apr 1, 2014 at 11:13

1 Answer 1


You can for example:

  • Copy the YouTube shortcode from the old theme to your new theme.

    Locate the line (most likely in the functions.php file):

    add_shortcode( 'youtube', 'some_function' );

    and copy this line and the some_function() to your functions.php in your new
    theme or better yet - create a new plugin file including:

    /*Plugin Name: YouTube embed shortcode from old theme */
    add_shortcode( 'youtube', 'some_function' );
    some_function( $args = array(), $content = ''){ /* ...code... */}
  • Add a YouTube embed plugin with the same parameters.

  • Create your own plugin to handle this.

    Here's a poor man's version (untested):

    /*Plugin Name: YouTube embed shortcode - poor man's version */
    add_shortcode( 'youtube', 'ytb_sc' );
    if( ! function_exists( 'ytb_sc' ) ):
        function ytb_sc( $atts = array(), $content = '' )
           $atts = shortcode_atts( array(
               'id'      => '',             // default id
               'width'   => 640,            // default width (px)
               'height'  => 480,            // default height (px)
           ), $atts, 'ytb_sc' );
             // Sanitize input:
             $id      = esc_attr( $atts['id'] );
             $width   = (int) $atts['width'];
             $height  = (int) $atts['height'];
            if( ! empty( $id ) ) {
                $sc = sprintf( '[embed width="%d" height="%d"]%s%s[/embed]',
                               $id );
            } else {
                return __( 'Missing YouTube ID!' );
            // Output
            return $GLOBALS['wp_embed']->run_shortcode($sc);

Hope this helps!

  • unfortunately it didn't work =[ ... I think my theme (Explicit) has some code blocking any kind of change to it's natural settings for youtube for some reason. It's even blocking the plugin jetpack from working. I'll just have to change it one by one! =/ Thanks a lot for your answer! Apr 4, 2014 at 18:44
  • ok, what method did you try?
    – birgire
    Apr 4, 2014 at 18:47
  • oh and this is the code i found on functions.php on my old theme (LeetPress) add_shortcode('youtube', 'shortcode_youtube'); function shortcode_youtube($atts) { $atts = shortcode_atts( array( 'id' => '', 'width' => 600, 'height' => 360 ), $atts); return '<div class="video-shortcode"><iframe title="YouTube video player" width="' . $atts['width'] . '" height="' . $atts['height'] . '" src="youtube.com/embed' . $atts['id'] . '" frameborder="0" allowfullscreen></iframe></div>'; } Apr 4, 2014 at 18:47
  • I tried creating a plugin with the code you gave me, tried to create a plugin with the code of my old theme, tried installing TinyMCE, hmmm and installing many other plugins for youtube embed Apr 4, 2014 at 18:48
  • my website keeps on showing the message "Please enter the url to a YouTube video." where the videos should be. =[ Apr 4, 2014 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.