Hi,
{{post_title}}
and other template tags only work within the Header Element (not block elements).
That said, you’ll need a plugin that displays dynamic text to display within your Block element layout.
Alternatively, you can write your own shortcodes that display dynamic texts.
Example: “A shortcode that displays the page/post title”
function dynamic_title_function( $atts ) {
$atts = shortcode_atts(
array(
'tag' => '',
'style' => '',
), $atts, 'dynamic_title' );
$tag = $atts['tag'];
$style = $atts['style'];
$output = '';
if(!empty($tag)){
$output = sprintf( '<%1$s style="%3$s"> %2$s </%1$s>',
$tag,
esc_html( get_the_title() ),
$style
);
} else {
$ouput = esc_html( get_the_title() );
}
echo $output;
}
add_shortcode( 'dynamic_title', 'dynamic_title_function' );
With this snippet, you can use [dynamic_title tag="h1" style="color:red;"]
on your block element to display page title.
Note: I’ve written this shortcode in a way where if you only want the string, you can just use [dynamic_title]
without the attributes.
You can also make this for other things like meta terms.