wordpress-video-embed-size

How to change WordPress default embed size using filters

on February 2, 2011

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.

ADVERTISEMENT
ADVERTISEMENT

About Shailan.com Staff

Shailan.com is a design blog about WordPress and web design. We regularly write about wordpress, plugins, themes, web design resources, php, css, jquery, adsense and more.. If you want to get notified about our posts, be sure to subscribe to our feed or follow us on facebook.

Share Your Thoughts

Your email address will not be published.

16 thoughts on “How to change WordPress default embed size using filters”

  1. Pingback: Changing the default wordpress youtube embeded video dimensions | Technology & Programming
  2. Nick Hiley says:

    Hey,
    Thanks for this snippet! In my function.php file, I’ve allowed video embeds in the excerpt but this snippet doesn’t affect the video in the except. What code would I need to add to do this globally?

    Thanks