-
Hi!
I would like to add text at the end of post titles.
Just like in the screenshot below.
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.
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/
-
David
Hi there,
what is the text that you want to add ?
-
This is one simple word. For example: “opinion”.
-
David
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.
-
David
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>
- You must be logged in to reply to this topic.