Code looks fine but doesn't work

I did not write this code, but it looks okay to me. It is used in a site template and I believe its purpose is to call and display testimonials, but only if the current page being displayed is the home page. It is not working. It is displaying the testimonials on all pages. Any ideas?

<?php if(is_front_page()): ?>
<div class="testimonials">
<?php echo do_shortcode('[testimonials_slider refresh_interval=10 show_controls=true]'); ?>
<?php else: ?>
<?php get_sidebar(); ?>
<?php endif; ?>

It occurs to me it might be worth mentioning…

Commenting out (requires both html and php commenting) the top half (pre-else) portion of the if statement does in fact remove the testimonials from the home page, but they are still on every other page. I didn’t really pay attention to the back pages on the site before I started because the client only requested a change on the home page. I’m now wondering if the code is doing exactly what it is supposed to do and something else on the site is causing the testimonials to appear on all the back pages.

You need to use { and } rather than colons.

<?php if (is_front_page() == TRUE) { ?>
<div class="testimonials">
<?php echo do_shortcode('[testimonials_slider refresh_interval=10 show_controls=true]'); ?>
</div> <?php } ?>

OP is using the alternate syntax. There’s nothing wrong with that.

1 Like

I prefer especially in templates the alternative syntax.
<?php endif; ?> is more striking then <?php } ?> between your HTML

It turns out, the code was fine. The testimonials were being applied to the back pages via a widget named “Pages Sidebar”. I struggled to find it because they were showing up at the bottom, nowhere near the side.

I commented the entire thing out because I want control over where the testimonials appear on the front page. I was able to put them back into the home page via the shortcode either as text or in a content block. Now my problem is that the testimonials are not visible unless you are logged in. Pretty confusing as WP is not like Drupal, It doesn’t have granular security settings for things like, only shot this type of content on this page or that page. It’s not a caching problem. The site isn’t cached.

Sponsor our Newsletter | Privacy Policy | Terms of Service