-1

I want to detect the taxonomy term from my site url. For exampe if u consider this url, http://xxxxyyzzz.com/medicines/tablets/ I can detect the taxonomy 'medicines' but am unable to detect the taxonomy term 'tablets' using this code..

if(is_tax( 'medicines', 'tablets')) { echo "You are on tablet page"; }

Sohail Malik
  • 305
  • 1
  • 2
  • 12

1 Answers1

1

I'm a little confused by your question but I'll try to answer it as best I can.

"I want to detect the taxonomy term from my site url.". You're going about this in the wrong way. You'd end up with an incredibly long conditional if you tried using is_tax() for each term.

There are different ways you may want to approach this depending on where you're placing the code. Example:

// Check we're on a term page for the medicines taxonomy.
if ( is_tax( 'medicines' ) ) { // consider a singular name?

    // Get the current term object.
    $term = get_queried_object();

    // do something with the term...
    echo $term->name;

}
Nathan Dawson
  • 18,138
  • 3
  • 52
  • 58