Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress editor shortcode for custom html ouput

Tags:

php

wordpress

I need help creating Wordpress function to make shortcode [youtube-id=ID] in post editor output the following html code with ID value included:

<iframe width="420" height="315" src="https://www.youtube.com/embed/ID?rel=0" frameborder="0" allowfullscreen></iframe>

1 Answers

in your functions.php

function YouTubeID($atts, $content = null) {
    extract(shortcode_atts(array('id'=>''), $atts));
    return '<iframe width="420" height="315" src="https://www.youtube.com/embed/'.$id.'?rel=0" frameborder="0" allowfullscreen></iframe>';
}
add_shortcode('youtube', 'YouTubeID');

wherever you want the video the shortcode will be:

[youtube id="THE_ID"]
like image 167
Moishy Avatar answered May 20 '26 13:05

Moishy