WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried to set up different video oembed size for content and sidebar. I can set up video size with embed_defaults filter. But this filter works for the whole site and I need to have smaller video size in my sidebar. So, I tried to add action to loop_start and check here if main loop is running.

function test_main_loop( $query ) {
  global $wp_the_query;
  if ( $query === $wp_the_query ) {
    add_filter( 'embed_defaults', 'big_embed_defaults' );
  else {
    add_filter( 'embed_defaults', 'small_embed_defaults' );
add_action( 'loop_start', 'test_main_loop' );

Can I call add_filter() inside add_action() function? Everything works, but I am not sure if it the right solution? Or do you have other idea how to achieve different video sizes only with WordPress oembed support (without plugin)? Thank you for your help...

share|improve this question

A better solution would be to add the filter hooks before the actual call in the template and removing theme when done meaning in your theme before you call your sidebar using dynamic_sidebar or what ever use this:

add_filter( 'embed_defaults', 'small_embed_defaults' );
remove_filter( 'embed_defaults', 'small_embed_defaults' );

and the same with your main loop:

add_filter( 'embed_defaults', 'big_embed_defaults' );
remove_filter( 'embed_defaults', 'big_embed_defaults' );
share|improve this answer
Yes, it would be possible, thank you for your answer. But is there any "plugin" solution (without editing theme files)? I also found another solution - set only one size and for sidebar create function which will replace size in HTML. But in this case I have to modify theme files... – user3316 Oct 19 '11 at 21:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.