Skip to content
Advertisement

WordPress conditional statement how to exclude several page templates and also a taxonomy archive page

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') ) )

Advertisement

Answer

I highly recommend reading the “Docs” first. It’ll help you get your question answered quicker!

“I need to change it to also exclude an archive page for my Custom Post type”

To exclude an archive page you could use !is_archive() and !is_post_type_archive(). To include it, then remove the !.

is_archiveDocs

and

is_post_type_archiveDocs

if (is_post_type_archive('name-of-your-custom-post-type')){

  // Write your code

}

Since you mentioned something about taxonomy, although it was not clear, is_tax() could be another conditional check that might be useful.

is_taxDocs

Again I highly recommend reading the “Docs”, or at least, include the details of your problem in a clear way so that people could help you faster.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement