Skip to content

Instantly share code, notes, and snippets.

@seothemes
Created November 19, 2022 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seothemes/2b12201d0bd2b883bdbcafa9fc0a2048 to your computer and use it in GitHub Desktop.
Save seothemes/2b12201d0bd2b883bdbcafa9fc0a2048 to your computer and use it in GitHub Desktop.
Add custom shortcode support to paragraph block
<?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