How to change WordPress default embed size using filters

Embedding videos from video sites to your posts is a very simple task in WordPress. You can easily embed videos just pasting URL of the video to your posts. It automatically displays the video depending on your media settings. What if you wanted a different video size in single posts?

Then you will need to use a filter to change embed default dimensions depending on context. In this post, I will show you how to simply change WordPress default embed size for single posts. You can expand this trick to use with other contexts.

Simply open functions.php in your theme folder to create our filter.

Paste the following code:

function mycustom_embed_defaults($embed_size){
	if( is_single() ){ // If displaying a single post
		$embed_size['width'] = 586; // Adjust values to your needs
		$embed_size['height'] = 500; 
	return $embed_size; // Return new size

add_filter('embed_defaults', 'mycustom_embed_defaults'); 

Save it and then visit your post page. It will display automatic embeds using new size you define on your single post pages. For home page wordpress will use default size, but in single post view,
WordPress will use default embed size you defined in the functions.php file.

Please note that, auto-embed embeds videos proportionally. So it will use either width or height for limiting video size. Output may not fit exact dimensions you declared here. I suggest using height a large value. This way you can be sure it will always use width constraint.

I hope you found this useful.

NS Weight Release