[Support request] Template Tags not working

Home Forums Support [Support request] Template Tags not working

Home Forums Support Template Tags not working

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1579226
    Mark

    I made a Block Element to use as a page header. Hooked it into generate_after_navigation. It’s appearing as it’s supposed to but the template tag just shows as text…{{Post_title}}

    It’s not pulling in the actual title like it did in “the old days”.

    Is there another way to use the template tags now?

    Thanks.

    #1579248
    Elvin
    Staff
    Customer Support

    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.

    A wise man once said:
    "Have you cleared your cache?"

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.