Youtube dimensions wordpress
Asked Answered
T

5

10

Is it possible to change the default embed dimensions of an youtube (or another video) in Wordpress for your current theme? I've searched for a plugin and some code, but I can't seem to find any.

What I mean is the default embed size used when you just paste an youtube url in an post or page.

Taligrade answered 30/9, 2011 at 17:30 Comment(0)
L
2

To change the default embed size go to Settings > Media and just set a fixed width/height.

You also have the shortcode

[youtube=http://www.youtube.com/watch?v=0Bmhjf0rKe8&w=640&h=385]

where you can manually insert width and height as params. This shortcode will overwrite the default WP settings.

Linette answered 30/9, 2011 at 17:39 Comment(3)
Thank you, works like a charm. No wonder I could not find a plugin if it is default functionality.Taligrade
I've tried both of these methods and neither work in the current version of WordPress (3.5.1).Gallon
According Wordpress documentation on this topic this should be still working. May you have any plugin that can be bugging this?Linette
R
11

Open your theme’s functions.php file, and add the following code:

if ( ! isset( $content_width ) ) $content_width = 600;

Remember to change the number 600 appropriately for your theme. It is the maximum width in pixels for your content area.

Once you do this, WordPress will automatically use that for the maximum width of your oEmbed elements (youtube videos, slideshare, etc).

via wpbeginner.com

Rudimentary answered 15/11, 2013 at 17:30 Comment(1)
How about the height?Uzbek
H
10

The media settings have been removed. You can do it with a filter however.

function mycustom_embed_defaults($embed_size){

    $embed_size['width'] = 600; // Adjust values to your needs
    $embed_size['height'] = 500; 

    return $embed_size; // Return new size 
}

add_filter('embed_defaults', 'mycustom_embed_defaults');

Taken from here http://shailan.com/2154/change-wordpress-default-embed-size-using-filters/

Hiding answered 18/3, 2013 at 2:45 Comment(1)
I tried this and although it worked for the width, it didn't work for the height, which seems stuck at 281 regardless of what I put.Nanci
S
3

The currently accepted answer has an example that uses the following shortcode:

[youtube=http://www.youtube.com/watch?v=0Bmhjf0rKe8&w=640&h=385]

The shortcode [youtube] only works if you have the Jetpack plugin installed.

To make it work with WordPress with no Jetpack you can use the built-in [embed] shortcode like this:

[embed width=640 height=385]http://www.youtube.com/watch?v=0Bmhjf0rKe8[/embed]
Statistics answered 12/5, 2015 at 12:1 Comment(0)
L
2

To change the default embed size go to Settings > Media and just set a fixed width/height.

You also have the shortcode

[youtube=http://www.youtube.com/watch?v=0Bmhjf0rKe8&w=640&h=385]

where you can manually insert width and height as params. This shortcode will overwrite the default WP settings.

Linette answered 30/9, 2011 at 17:39 Comment(3)
Thank you, works like a charm. No wonder I could not find a plugin if it is default functionality.Taligrade
I've tried both of these methods and neither work in the current version of WordPress (3.5.1).Gallon
According Wordpress documentation on this topic this should be still working. May you have any plugin that can be bugging this?Linette
W
2

They've got rid of the fixed width/height option in the media settings of the new version of Wordpress. Not sure why. It was useful!! Shortcodes don't seem to work either.

Whirlabout answered 5/2, 2013 at 20:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.