I am trying to output a logo depending on which page is being viewed.

<?php if ( is_page('home') || is_page('services') ) { ?>
    <div class="col-md-2 col-sm-4">
        <?php ci_e_logo('<h1 class="logo ' . get_logo_class() . '">', '</h1>'); ?>
    </div>
<?php } 
else { ?>
    <div class="col-md-2 col-sm-4">
        <h1 class="logo imglogo">
            <a href="http://websiteaddress.com">
                <img src="<?php echo get_bloginfo('template_directory');?>/images/picturehere.png" alt="title here"></a>
            </h1>
    </div>
<?php } ?>

The code above works fine, but how do apply the logo image swap on the sub-pages of the ‘services’?

7

You can do that with $post->post_parent. You will have to check if child page’s parent is Services page. So this is how you will check it.

I assumed 123 in following code is page ID of your services page. Replace it with actual ID.

if ( 123 == $post->post_parent ) { ?>
    <div class="col-md-2 col-sm-4">
        <?php ci_e_logo('<h1 class="logo ' . get_logo_class() . '">', '</h1>'); ?>
    </div>
<?php }

Leave a Reply

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