Question about a piece of PHP code in a WordPress template file.
The template contains this code:
<h1><?php the_title(); ?></h1>
I want the title only be printed if the title is not “Home”.
But this code doesn’t work:
<?php if (the_title()!='Home'); ?>
<h1><?php the_title(); ?></h1>
<?php endif; ?>
the_title()echoes, it doesn’t return its title.Use
get_the_title()instead.As an aside, it looks like you’re trying to detect if you’re on the home page. Checking against a title can be flaky, as that can change.
Use
is_home()instead.