I have code in my header that excludes certain templates. I need to change it to also exclude an archive page for my Custom Post type. The file name for the archive template is taxonomy-press_category.php
.
But I don't know how to also include my custom post type archive template.
I am currently using:
if ( ! is_page_template ( array( 'homepage_template.php', 'services_template.php') ) )
My Answer:
You can modify the conditional statement to exclude both page templates and the taxonomy archive page for your custom post type by adding another condition using the `is_tax()` function. Here's how you can do it:
php
if ( ! is_page_template( array( 'homepage_template.php', 'services_template.php' ) ) && ! is_tax( 'press_category' ) ) {
// Your code here
}
In the above code, `is_tax( 'press_category' )` checks if the current page is the taxonomy archive page for the 'press_category' taxonomy. You can replace 'press_category' with the slug of your custom taxonomy.
This conditional statement will exclude the specified page templates and the taxonomy archive page for your custom post type from executing the code inside the if block.
Rate this post
5 of 5 based on 8332 votesComments