Last active
November 14, 2023 13:29
-
-
Save nicomollet/02c1a0e3920f3c889d8693a1dbd1af53 to your computer and use it in GitHub Desktop.
WordPress block editor: add data-modal attribute to button block.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function render_block_button_datamodal( string $block_content, array $block ){ | |
if ( 'core/button' === $block['blockName'] && ! empty( $block['attrs']['dataModalAttribute'] ) ) { | |
$block_content = str_replace('<a ', '<a data-modal="'. esc_attr($block['attrs']['dataModalAttribute']) . '"', $block_content); | |
} | |
return $block_content; | |
} | |
add_filter( 'render_block', 'render_block_button_datamodal', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment