How Do I Center a YouTube Video in WordPress?
If you run a WordPress powered website you have probably wanted to embed a YouTube video at one time or another. Video can add interactivity and excitement to a blog post. Luckily, WordPress and YouTube make this a very easy course of action. Centering your YouTube video can be a bit tricky though, especially if you don’t know any coding. This article will teach you a very simple fix though. It will ensure you can center any YouTube video, or any object at all, for that matter.
First you have to get the video into your post. You go to YouTube, click embed (under video), choose your options and copy the HTML code. You then take that code and paste it into the WordPress visual editor. Remember you have to set to HTML, using the button in top right corner. Then you simply paste in your YouTube embed code. Now you have the video in your post or page.
Once you have that done you can switch back to the visual tab on the WordPress editor. You will see your video (or object) as a large yellow box. Ideally, you could simply click on that box and click the center button on the editor. Unfortunately, that doesn’t work. I am not sure exactly why, but it is probably because the center command in WordPress inserts HTML code that the object doesn’t recognize. For example, already if you switched back over to the HTML editor and wrapped the object in < center > tags, it won’t work.
The fix is pretty simple though. You just have to navigate back to the HTML part of your editor. You won’t see the yellow box now you will see the embed code for the video. Right before the embed code, go into:
And then after the end of the embed code:
When you switch back to your visual editor you will notice the yellow box is centered! Now that you have learned this code you can center any YouTube video or other object in each of your posts. Use it often enough and it won’t be long until you have the code memorized. If you aren’t comfortable with HTML, then write the above code down right now. If you are at your computer, add it to a text file so you can copy and paste easily. Try it on your next blog post and let me know how it works.