I am including a partial file both in header.php and in footer.php with get_template_part('content-form');

Is there an if clause I can use to check from where the file is being called? If it is called from within footer.php, then I would like to add a class name.

<div class="default-class <?php if (called_from_footer) echo 'footer-class'; ?>">
</div>

I could do this and style accordingly if there isn’t a better solution, I am just curious:

<div class=footer-container">
    <?php get_template_part('content-form') ;?>
</div>

4 s
4

This is not a true solution to your problem (checking which template loaded another), but it will work to test if the footer has been loaded or not, and thus if it’s loading your partial:

if ( did_action( 'get_footer' ) ) echo 'footer-class';

Leave a Reply

Your email address will not be published. Required fields are marked *