Skip Navigation

[Resolved] Determine if the Current page is a Custom Taxonomy Archive in PHP

This thread is resolved. Here is a description of the problem and solution.

Problem: I have some PHP code that filters the title text for archive page templates. I would like to use a conditional that will determine whether or not the current page is a custom taxonomy archive.

Solution:
For custom taxonomies, you must use "is_tax". You should be able to find the correct syntax for is_tax() in the sample code linked below:

Relevant Documentation:
https://developer.wordpress.org/reference/functions/is_tax/
https://developer.wordpress.org/reference/functions/is_tax/#user-contributed-notes

This support ticket is created 7 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Kacey 7 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#581145

I'm trying to take the "Archive:" out of the page titles for archive pages. I've succeeded in removing it with some php in the functions file for category, tag, and author archives. However, I'm also using a custom taxonomy and I can't seem to figure out how to write that in. Here's what I have that's working for the three other types of archives:

add_filter( 'get_the_archive_title', function ($title) {

    if ( is_category() ) {

            $title = single_cat_title( '', false );

        } elseif ( is_tag() ) {

            $title = single_tag_title( '', false );

        } elseif ( is_author() ) {

            $title = '<span class="vcard">' . get_the_author() . '</span>' ;

    return $title;

My custom Taxonomy is called Types, so I was guessing that it would be something like this:

        } elseif (is_types() ) {
            $title = single_types_title ('', false );
    }

but that's not working. Any advice?

Best,
Allison

#581262

Hi, you can refer to the WordPress documentation for is_category():
https://developer.wordpress.org/reference/functions/is_category/

Down the page you can see "More Information", where it says:
For custom taxonomies, you must use "is_tax".
Link - https://developer.wordpress.org/reference/functions/is_tax/

You should be able to find the correct syntax for is_tax() in the sample code here:
https://developer.wordpress.org/reference/functions/is_tax/#user-contributed-notes

#582562

Thank you!