Home / functions.php / Creating oEmbed-Based shortcodes
  • How to Creating oEmbed-Based shortcodes

    creating-oembed-based-shortcodes

    Adding this snippet to the functions.php of your wordpress theme will create a youtube shortcode. This is a simple sample of an oEmbed-Based shortcode.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    add_shortcode( 'youtube', 'my_youtube_shortcode' );
    function my_youtube_shortcode( $atts ) {
        global $wp_embed;
        if ( empty($atts['id']) )
            return '';
        // Construct the YouTube URL
        $url = 'http://www.youtube.com/watch?v=' . $atts['id'];
        return $wp_embed->shortcode( $atts, $url );
    }
    
    ( click code to copy )

    wordpress snippet : PHP

    <>
    [youtube id="000000"]
    

    ( WordPress codex functions, hooks, in this snippet. )

    add_shortcode, _e, wp,