[wp-hackers] Using different filter values on website

Pavel Hejn pavelevap at post.cz
Thu Sep 29 15:42:00 UTC 2011


Hi,

I tried to set up different video oembed sizes for content and sidebar. I have CPT "video" and 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 and bigger video size when listing items from my CPT in main content. So, I tried to add function to loop_start and check 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 is the right solution (best approach)? Or do you have any other idea how to achieve different video sizes on website only with WordPress oembed support (without plugin)? Thank you for your help...

Pavel


More information about the wp-hackers mailing list