Apply filter to an element with specific class

Viewed 49

I'm using this filter

add_filter( 'render_block', function( $block_content, $block ) {
    if ( 'generateblocks/headline' === $block['blockName'] ) {
        $block_content = str_replace( '<a ', '<a target="_blank" rel="nofollow" ', $block_content );
    }

    return $block_content;
}, 10, 2 );

But it applies on all blocks 'generateblocks/headline' that are links.

I would like to know if it's possible to make this filter only working for a specific CSS class ?

I'm a newbie on PHP so thanks a lot for your help !

Samuel

0 Answers
Related