Conditional Template Classes in WordPress

by, mira

For singe post vs feed:

<header class="entry-header 
  <?php 
    if ( is_single() ) : 
      echo 'container'; 
    endif; 
  ?>
">
</header>

For context, this code would be inside of

📁 theme > 📁 template parts > 📄 content.php

Where 📄 content.php is being called within multiple templates:

📄 index.php
📄 single.php

The 📄 content.php conditionally displays content based on what template it is being displayed inside of.

%d bloggers like this: