Create Simple Shortcode In WordPress

We may come across some situations to use the shortcodes,even if you are a beginner, you can try to create your own shortcodes with below example.

The following short code will help you to embed from various video websites like vimeo, youtube etc.

/* Video Embed */
add_shortcode('video_embed', 'embed_video'); // This then accepts the function below embed_video and allows the user to enter the shortcode in there post.
function embed_video($atts){
    $atts = shortcode_atts(
        array(
            'src'       => ' ', // This is left blank but if you want to add a video as a default, that is up to you.
            'width' => '600', // Default Width
            'height'    => '338', // Default Height
            'title' => 'There is a video in this post.' // This a great default caption to have for your RSS Feeds. That way users will know that a video is available in the post to watch.
        ), $atts);
        return '
        <embed src="'.$atts['src'].'" type="application/x-shockwave-flash" width="'.$atts['width'].'" height="'.$atts['height'].'" allowscriptaccess="always" allowfullscreen="true"></embed>
        <h4>'.$atts['title'].'</h4>
        ';
}

The above functions can be copied to functions.php in your wordpress theme.

To display the video, the following shortcode can be used.

[video_embed src="http://www.youtube.com/watch?v=6WC5ufuc6m0" width="680" height="360" title="Sample Video"]