Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

How to add text to posts title?

  • Hi!

    I would like to add text at the end of post titles.

    Just like in the screenshot below.

    txt to the title

    I tried using elements module. I chose hook: generate_after_entry_title and generate_after_entry_header. The results were as shown in the screenshot below.

    txt below title

    My question is: how to add text to the post title? Can I use the elements module? In my case I would like to do this for all posts except one category.

    I have a page on your template GeneratePress, here is address: https://torian.pl/

  • Hi there,

    what is the text that you want to add ?

  • This is one simple word. For example: “opinion”.

  • And is that one simple word the same for all posts ?

  • Not for all.
    As I wrote at the beginning: In my case I would like to do this for all posts except one category.

    That’s why the Display Rules i Element are perfect. But there is no such hook.

  • Ok. Theres no action hook there as its simply returning the_title.
    But in GP we have a filter hook to allow you to change the HTML.
    And you can use it in a PHP Snippet like so:

    add_filter('generate_get_the_title_parameters', function($params) {
        if ( ! is_singular() && ! in_category('your-category') ) {
            $params = array(
                'before' => sprintf(
                    '<h2 class="entry-title"%2$s><a href="%1$s" rel="bookmark">',
                    esc_url( get_permalink() ),
                    'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : ''
                ),
                'after' => '<span> - your text here</span></a></h2>',
            );
        }
        return $params;
    });

    This will apply to your archive pages, and here:

    ! in_category('your-category')

    you specify the category you DONT want it applied to.

    and here:

    'after' => '<span> - your text here</span></a></h2>',

    you specify your additional text with markup if needed ie. <span> - your text here</span>

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