Created
November 19, 2022 00:40
-
-
Save seothemes/2b12201d0bd2b883bdbcafa9fc0a2048 to your computer and use it in GitHub Desktop.
Add custom shortcode support to paragraph block
This file contains hidden or 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 | |
declare( strict_types=1 ); | |
namespace Company\Project; | |
use function add_filter; | |
use function gmdate; | |
use function str_replace; | |
add_filter( 'render_block_core/paragraph', __NAMESPACE__ . '\\render_paragraph_block', 10, 2 ); | |
/** | |
* Modifies front end HTML output of block. | |
* | |
* @since 0.0.2 | |
* | |
* @param string $content Block HTML. | |
* @param array $block Block data. | |
* | |
* @return string | |
*/ | |
function render_paragraph_block( string $content, array $block ): string { | |
$tags = [ | |
'[year]' => gmdate( 'Y' ), | |
]; | |
foreach ( $tags as $tag => $value ) { | |
$content = str_replace( $tag, $value, $content ); | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment