Archived topic
check whether on taxonomy page
6 replies · Started by Marco on January 31, 2019
Hello
what hook do I need to use in order to be able to check whether I'm on a tag archive/taxonomy page - as I understand is_tax() should give me the answer but I don't know where to put it in my custom functions file
Hi there,
If you're using our Hook Elements, you can choose your taxonomy in the Display Rules: https://docs.generatepress.com/article/hooks-element-overview/
Otherwise, is_tax() is the right function to check. How you use it depends on what exactly you're trying to do.
Thanks Tom - I basically like to have a function where I can check if I'm currently on a taxonomy archive page - pre-get-post didn't work.
What does the function do if it detects you're on a taxonomy page?
let's say I'm on a page like: http://localhost/cms/wp-vitus/tag/project-mgmt/ - a taxonomy page - in the right sidebar I'd like to show all the other post titles that also have the tag slug "project-mgmt" - kind of a contextual widget that is created/populated dynamically - I don't whether it is even possible to dynamically ad a widget to the right sidebar - however first I need to figure out whether I'm on a taxonomy page or not.
wp_head, pre_get_posts don't seem to work when running is_tax()
I might got a little closer - `is_tag()' seems to do the trick to find out whether I'm on a tag page
A plugin like this might be worth checking out: https://wordpress.org/plugins/content-aware-sidebars/