Blog > Website Design > WordPress Conditional Tags : If Page Template Is Then
Display or hide content according to which WordPress Page Template is being used for a page.
Example Uses
I use this in my portfolio section in the top navigation bar, I have a separate custom template for all portfolio pages. I use this code to only display relevant content on the portfolio pages, i.e. The Navbar on the left, custom header information, certain JavaScript like my slider for the individual boxes, etc.
WP Code
<?php if (is_page_template('mycustomtemplate.php') ) { ?>
<p>Apples</p>
<?php } else { ?>
<p>Oranges</p>
<?php } ?>
Code Implementation
Make sure to change “mycustomtemplate.php” to your actual custom template name. You can use this anywhere in your WordPress Template files both custom Templates or original Theme files. Example: single.php, archives.php, etc.





Leave a Reply