Site logo

Archived topic

Show something after Post Title

1 reply · Started by René on June 12, 2022

Viewing posts 1–2 of 2

Hey,

In the codes I saw that the function "the_title" takes parameter for before and after. Where can I enter it? In the dynamic text type field i only can edit the before, not the after.

And can the parameters only be used for certain posts/categories?

Code

Hi there,

for the GP Dynamic Text type you would need to use the generate_dynamic_element_text filter.
For example.

Give the Headline block that you want to filter a CSS Class eg. dynamic-title

Then you can use that in this PHP Snippet

add_filter( 'generate_dynamic_element_text', function( $text, $block ) {
    if ( ! empty( $block['attrs']['className'] ) && 'dynamic-title' === $block['attrs']['className'] ) {
        $before = 'your before content';
        $after = 'your after content'
        $text = $before . $text . $after;
    }

    return $text;
}, 10, 2 );
This archived topic is closed to new replies.