Home > Blockchain >  WordPress conditional statement how to exclude several page templates and also a taxonomy archive pa
WordPress conditional statement how to exclude several page templates and also a taxonomy archive pa

Time:10-10

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

CodePudding user response:

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.

CodePudding user response:

Thank you so much for your references, that helped.

This is the code that finally worked for me:

  if( !is_page_template ('homepage_template.php') &&  !is_page_template( 'services_template.php' )  &&  !is_tax( 'press_category' )) { 

  • Related