Archived topic
add action conditionally for a right sidebar heading
6 replies · Started by Elaine on March 25, 2019
How do I add action conditionally for a right sidebar heading on Blog Archive & Single Posts?
Using GP hooks, here is what I have so far, but this will show up in every right sidebar, and I have more than one. Interested in how to write it conditionally to only appear on Blog.
add_action( 'generate_before_right_sidebar_content','es_insert_title_right_sidebar' );
function es_insert_title_right_sidebar() { ?>
<h4 class="es-right-sidebar-title">Filter Blog Posts</h4>
<?php }
Hi there,
you can use Conditional tags:
https://docs.generatepress.com/article/using-hooks-conditional-tags/
Or better still use the Hook Element which has the display rules built in:
https://docs.generatepress.com/article/hooks-element-overview/
I would go for the latter :)
Thanks David
I was able to add the heading in the right sidebar & a filter list menu under by applying the Widget Context plugin to an HTML widget and a Tag Cloud Widget. So the list menu is created from a Tag Cloud, in order to be able to filter Blog Posts.
Now I am unhappy with the result in terms of the Breadcrumbs. If I click on a tag of 'Mindset' in the sidebar, instead of Breadcrumb: Home > Blog > Mindset, it appears Home > Mindset.
Of course the url of that Post is: name-of-site/tag/mindset/. So I guess i've taken the Blog reference out of it altogether.
How can I filter these Blog Posts so that I can maintain a Blog Breadcrumb logic?
I'm using Tags, but would be in the same boat with Categories . . .?
Thank you in advance for your help!
I forgot to mention I already have a Hook Element for Yoast Breadcrumbs activated for a location of 'everywhere'.
Hi there,
I'm not sure how to alter the output of the breadcrumbs themselves, unfortunately. That might be a question for Yoast support.
This article might help: https://kb.yoast.com/kb/implement-wordpress-seo-breadcrumbs/
I see there's a "Show blog page" option you can select.
Thank you!
You're welcome :)