I want to write code only if it is single and part of the custom taxonomy. Here's how my custom taxonomy edit URL looks like:


I tried many different ways but not working. Here's one example:

if ( is_single() && has_term( ' ', '53' ) )

What's wrong going on? For the regular category, it's working with the in_category function. I don't know how things work for custom taxonomy type. How can I achieve this?


The first problem is that you've got a space in the first argument of has_term(). If you want to check for any term then you need to pass an empty string, but a space is not an empty string. Then, as documented, the second argument needs to be the taxonomy name.

This should work:

if ( is_single() && has_term( '', 'us_pf_category' ) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.