简体   繁体   中英

Exclude multiple page templates

I need to exclude a child theme function from certain page templates.

I can exclude one template like this

if (!(is_page_template( 'templates/my_page_template.php' )))
{ // the child theme function here
 ....
}

How do I add more page templates to exclude statement?

if (
    !(
    (is_page_template( 'templates/my_page_template.php' ))   or 
    (is_page_template( 'templates/my_page_template1.php' ))   or 
    (is_page_template( 'templates/my_page_template2.php' ))   or 
    (is_page_template( 'templates/my_page_template3.php' ))   or 
    )

)
{ // the child theme function here
 ....
}

The is_page_template function accepts an array as argument. See here: https://developer.wordpress.org/reference/functions/is_page_template/

You can do something like:

if ( ! ( is_page_template( array('templates/my_page_template.php', 'templates/my_page_template2.php') ) ) )
{ // the child theme function here
  ....
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM