Video sharing sites like YouTube provide embed code for videos in iFrame format now. It was really easy to embed YouTube videos using old code method. Just copy and paste the embed code and the video is ready to use in posts. But it is not possible to directly insert iFrame code for videos in WordPress visual editor.


 

wordpress videos


If you ever tried to insert videos in your posts using WordPress post editor, you might have noticed that when you paste the code in HTML mode of editor and switch back to visual mode , the video doesn’t shows up and the video code gets disappeared . If you also face such problems in inserting videos to posts then here are 4 ways to embed videos from YouTube and other video sharing sites to WordPress blog post editor. You can choose any method which you find easy for you.


Add YouTube Videos to WordPress Blog Post Editor 1. Using oEmbed Method oEmbed is an easiest way to embed videos to WordPress blog posts.


oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.


To embed videos using this method, follow the instructions given below:

  1. Go to YouTube.com and open any video that you want to insert into blog post. At the bottom of the video click on Share button. A short video URL will be displayed. Don’t copy this URL but click Show options link and check on Long link. Now copy the long video URL.
  2. Paste the long URL that you copied in last step in WordPress post editor in Visual mode but not in HTML mode. When you paste the copied URL in post editor it may be hyperlinked. You need to select this link and click on unlink or press Alt+Shift+S.
  3. Now preview or publish the post and video should display in YouTube video player.

2. Using Old Embed Code Old embed code method is the oldest and easiest way to embed videos from YouTube to blog posts. To insert videos using old embed code, follow the instructions given below:

  1. Like in first method, open YouTube.com in your favorite web browser and open up any video. You will find a Share button at the bottom of the video. Click on that button.
  2. When you click on Share button, a drop down list of options will be displayed. You need to click on Embed button.
  3. After you hit the Embed button, you need to check on Use old embed code and copy the whole code for the video.

  4. Now go to WordPress blog post editor and open HTML mode. Paste the copied code here and preview the post to see confirm if the video is displaying properly or not.

If by chance video is not displaying using this method you can refer to other methods listed in this post.

3. Using WordPress Shortcode API WordPress Shortcode API is the set of functions to show content in posts or pages. You can read more about it in detail

here

.

Note:

If you are not comfortable with coding then I would not recommend you this method. You should better choose other 3 methods.

First you need to register the shortcode function and define its handler function in functions.php in your themes folder.

add_shortcode('myiframe', 'myiframehandler');

function myiframehandler($atts = null) {

 

extract( shortcode_atts( array(

'width' => 560,

'height' => 349,

'url' =>'',

'frameborder' => 0,

'scrolling' => 'no',

'marginheight' => '0',

'marginwidth' => '0'), $atts ) );

 

return '<iframe width="'.$width.'"

height="'.$height.'"

src="'.$url.'"

frameborder="'.$frameborder.'

marginheight="'.$marginheight.'

marginwidth="'.$marginwidth.'"></iframe>';

 

}

Copy and paste the above code in functions.php file and save it. Now you just need to place a shortcode in post editor to insert YouTube videos. You can refer to following example:

[myiframe url="https://www.youtube.com/embed/Q8U5WooVAok"]


4. Using iFrame Embed for YouTube WordPress Plugin Although I don’t recommend the use of plugins for simple tasks but if you are not comfortable with coding want to insert videos with relative ease then you can use iFrame embed for YouTube

WordPress plugin.

This plugin enables you to insert iframe code for a particular YouTube video on your WordPress blog. You can define the width and height of the video player in plugin settings page.

iFrame embed for YouTube adds a new red button to post editor. Whenever you want to insert videos to your posts, just hit on this button, paste the video URL and video is ready to use in posts.


wordpress videos