Show tags above title
-
Hi,
Can I show post tag only without link above post title in archive page?
Thanks!
-
Hi there,
You can try using the
generate_before_archive_titlehook to hook in your post tag texts.Here’s an example PHP snippet:
add_action('generate_before_archive_title',function(){ echo strip_tags( get_the_term_list( get_the_ID(), 'post_tag', '', ', ') ); });Here’s how to add PHP snippets – https://docs.generatepress.com/article/adding-php/
hi,
tried another hook, it works, thank you!
Hi,
How can I make this snippet NOT affecting search result page?
I see tags show on search result page before entry titles too.
Thanks!
You can set an if rule that checks if the page is NOT search page.
Example:
add_action('generate_before_archive_title',function(){ if(!is_search()){ echo strip_tags( get_the_term_list( get_the_ID(), 'post_tag', '', ', ') ); } });cool!
Have you sorted it out? Let us know if you need further help.:D
Yes, it works!
Great support as usual.
Nice one. Glad you got it sorted. π
Hi,
A small issue update.
The tag shows on all post page and archive page. It makes sense as the filter only rules out search page.
Can you update the filter to make it not display on post page too? It should only display on post archive page.
A simple design to show tags before title on a regular card-style post archive page is what we want.
Thanks, I’m not familiar with php.
-
This reply was modified 5 years, 1 month ago by
tolddsm.
Try this one.
add_action('generate_before_archive_title',function(){ if(!is_search() || is_single()){ echo strip_tags( get_the_term_list( get_the_ID(), 'post_tag', '', ', ') ); } });Or better yet, if you only want this on the Blog index page or archive pages, try this:
add_action('generate_before_archive_title',function(){ if(is_home() || is_archive()){ echo strip_tags( get_the_term_list( get_the_ID(), 'post_tag', '', ', ') ); } });Hi,
thanks for the great support. It works!
Gotta learn some PHP now. π
Gotta learn some PHP now.
Or any programming language. The principles in construction of conditions are the same. π
No problem. Glad to be of any help. π
-
This reply was modified 5 years, 1 month ago by
The topic ‘Show tags above title’ is closed to new replies.
