Adding content youtube into post articles often make us hassle to show the youtube video at the center position. By adding youtube content into articles can improve your website SEO ranking. But often the youtube iframe can’t appear in the right position so the embed video display becomes unattractive. Maybe you are a new blogger and do not understand about CSS feel frustrated when you want to put the video on your WordPress site.
The look of the standard embedded youtube video in WordPress article like the following picture:
The image above shows that the youtube video I embed are not in the middle position and looks unattractive layout. I will share a short trick to help you in setting the video embed position to be in the middle of your article content.
Table of Contents
Putting a Youtube Embed Video In Center Position
After getting the youtube embed code, add the div element to wrap the youtube iframe code like this:
1 | <div style="text-align: center;">Your youtube embed code</div> |
And the result of the installation of the above code makes the video in the right position now, that is in the middle. You can’t center the video by clicking the “align center” format button on the WordPress “visual editor” tab but still have to add the div element code using the manual on the “text editor” tab. And the results become as shown below.
Thus you have successfully created a video embed youtube right in the middle position
Installing Video Embed Youtube Full Width
To install video embed youtube for the full width you need to add a little CSS to set youtube iframe. This trick I get directly from the site css-tricks.com. Here’s how:
You should add this CSS code via the “Text editor” tab. Then add the following CSS code:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <style>.videoWrapper { position: relative; padding-bottom: 56.25%; /* 16:9 */ padding-top: 25px; height: 0; } .videoWrapper iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style> |
Wrap the embed youtube code with the div element as follows
1 2 3 | <div class="videoWrapper"> Your youtube embed code </div> |
Here the result:
In addition to the above, there is an easier manual way: by choosing the custom width and height iframe on the youtube option menu like the following image:
If you want to add an entire youtube video to your old article, you can add a jquery script to execute a youtube embed video on every article. You can read the tips here https://css-tricks.com/fluid-width-youtube-videos/
Leave a Reply