Change the automatic width and height for WordPress embedded videos

Isn’t it cool how you can easily copy and paste a Youtube, Vimeo, Flickr, Hulu or many other video services’ URLs and WordPress will automatically embed the video into your post? We think it really is, but if you do that, WordPress will take the settings from the video itself. That probably means that video width and height won’t be something you want in your article.

If embedding videos isn’t something you do on a daily basis, then changing those settings won’t be a problem – you will open the Text Editor and change the numbers in the code. On the other hand, if you have to embed videos often, this simple task might get on your nerves and that’s why you should automatize them.

Change width and hefight for embedded videos:

  1. Open your functions.php file
  2. Copy and paste the following code:
  3. function mycustom_embed_defaults($embed_size){
    $embed_size['width'] = 620;
    $embed_size['height'] = 360;
    return $embed_size;
    }
    
    add_filter('embed_defaults', 'mycustom_embed_defaults');
  4. Change the width and the height to any number in pixels you need for your site
  5. Save changes

After this, all you videos will automatically be resized to width and height you have set in the code.

A good thing (or a bad one, depending on how your site is configured) is that after saving the changes, all your videos will be resized. That includes the older ones you have already published.

That’s all, folks. Now go, copy and paste those embedded codes and enjoy how WordPress deals with your new videos. If you want to customize your videos even more, see how to show videos in popup and how to add lazy loading for your videos in WordPress.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *