PHP 20
Wp page template check - is_page_template By micha on 3rd July 2024 08:26:46 AM
  1. <div class="container">
  2.  
  3. <style>
  4.         .debug {
  5.                 margin-left: 15px;
  6.                 padding-left: 15px;
  7.                 border-left: 3px solid #d7470f;
  8.         }
  9. </style>
  10.  
  11. <div class="template-tests debug">
  12.         <?php
  13.         echo '<h2>Static Vars</h2>';
  14.         echo '<b>ID:</b> ' . get_the_ID() . '<br />';
  15.         echo '<b>is_page_template():</b> ' . is_page_template() . '<br />';
  16.         echo '<b>get_page_template:</b> ' . get_page_template() . '<br />';
  17.         echo '<b>get_page_template_slug:</b> ' . get_page_template_slug() . '<br />';
  18.         echo '<br />';
  19.  
  20.         if (is_page_template()) {
  21.                 echo '<h2>Yes, I am a page template</h2>';
  22.  
  23.                 if (is_page_template('templates/debug.tpl.php')) {
  24.                         echo 'I am the <i>debug.tpl.php</i> <br />';
  25.                 } else {
  26.                         echo 'I am not the <i>debug.tpl.php</i> <br />';
  27.                 }
  28.  
  29.         } else {
  30.                 echo '<h2>No, I am not a page template</h2>';
  31.         }
  32.         ?>
  33. </div>

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.