user992731
user992731

Reputation: 3520

Conditional stament for custom template page in WordPress

Is it possible to have a conditional if statement for a specific custom template page in wordpress?

Example:

 <?php if ( is_page('custom-home.php') ) { ?>

     //do this on my home page

   <?php } elseif ('custom-gallery.php') ) { ?>

      //do this on my gallery page

  <?php } else { ?>

  <?php } ?>

Upvotes: 1

Views: 779

Answers (1)

diggy
diggy

Reputation: 6828

is_page_template returns true when the specified template is being used:

if( is_page_template( 'custom-home.php' ) ) { 
    // do home stuff
} elseif( is_page_template( 'custom-gallery.php' ) ) {
    // do gallery stuff
}

Upvotes: 2

Related Questions