Here is the YouTube shortcode.
// youtube shortcode. function sc_youtube_single( $att, $content = null ) { return '<iframe width="640" height="480" src="' . do_shortcode( $content ) . '?rel=0" frameborder="0" allowfullscreen></iframe>'; } add_shortcode( 'youtube', 'sc_youtube_single' );
And you can add videos in your content like this.
[youtube]http://www.youtube.com/embed/XQu8TTBmGhA[/youtube]
You don't need to add ?rel=0 now in shortcode. Just paste youtube video link. You can also modify this function's code to specify more variables like widths, height, autoplay etc.
EDIT
I understand the issue and for that I have another code. Now you can post youtube URLs from address bar too. What this function will do is get video ID from posted URL and change it into embed code automatically. So your users do not have to get the embed code.
// Get YouTube video ID from URL function youtubeid( $url ) { $domain = parse_url( $url, PHP_URL_HOST ); $url = esc_url( $url ); if ( $domain == 'www.youtube.com' || $domain == 'youtube.com' ) { parse_str( parse_url( $url, PHP_URL_QUERY ) ); $youtubeid = $v; } else { $youtubeid = ''; } return $youtubeid; } // youtube shortcode. function sc_youtube_single( $att, $content = null ) { return '<iframe width="640" height="480" src="http://www.youtube.com/embed/' . do_shortcode( youtubeid ( $content ) ) . '?rel=0" frameborder="0" allowfullscreen></iframe>'; } add_shortcode( 'youtube', 'sc_youtube_single' );
?rel=0in your video links. You can also create a shortcode for adding videos into your posts. That way you will be able to customize it as you want.