Skip to content

Instantly share code, notes, and snippets.

@interactiveRob
Created April 7, 2023 02:54
Show Gist options
  • Save interactiveRob/bdfe543f77afb7ca4bacc3be8c5c40b6 to your computer and use it in GitHub Desktop.
Save interactiveRob/bdfe543f77afb7ca4bacc3be8c5c40b6 to your computer and use it in GitHub Desktop.
WP_HTML_Tag_Processor add_class
<?php
$hook = "render_block_someBlock";
add_filter( $hook, function($block_content, $block, $instance) {
$selector = explode(',', $blockInfo['selector'] ?? '');
$content = new WP_HTML_Tag_Processor( $block_content );
$content->next_tag( $selector );
$content->add_class( 'g-rich-text' );
$block_content = (string) $content;
return $block_content;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment