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…
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:and the same with your main loop: