I'm using a code snippet in functions.php
to modify all youtube embeds, in order to add extra player parameters. Prior to WordPress 5.6, the youtube blocks could be filtered with
if( "core-embed/youtube" === $block['blockName']) { // do something }
However, from WP 5.6 on the block name now is core/embed
and youtube
is a Variation.
I have tried if( "core/embed/youtube" === $block['blockName'])
as well as if($block['blockName'] == 'core/embed/youtube')
, but this doesn't work.
My full original code (adapted from this article) is:
function wpftw_modest_youtube_player( $block_content, $block ) {
if( "core-embed/youtube" === $block['blockName'] ) {
$block_content = str_replace( '?feature=oembed', '?feature=oembed&modestbranding=1&showinfo=0&rel=0&cc_load_policy=1', $block_content );
}
return $block_content;
}
add_filter( 'render_block', 'wpftw_modest_youtube_player', 10, 3);
I'm relatively new to Wordpress and to php, so any clarity is appreciated. I've tried to google an answer and consulted the Block Editor Handbook, but can't figure out the answer.
core/embed
and you need to check the other attributes for the active variation. Doesvar_dump($block);
help you identify where it is saved?youtube
- but how do I test for the variation's attribute? does something like$block['blockVariation']
make any sense?$block
. Does$block['blockVariation']
exist?$block['blockVariation']
does NOT exist .. I don't really have the php basics so I'm a bit at loss..