Hi Guys,
I wish to conditionally hide the page title from showing on my wordpress homepage.
Here’s my starting point: <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
Any help appreciated.
Hi Guys,
I wish to conditionally hide the page title from showing on my wordpress homepage.
Here’s my starting point: <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
Any help appreciated.
Try this:
<?php
$theCondition=false;
if($theCondition)
{
the_title( '<h1 class="entry-title">', '</h1>' );
}else{
the_title( '<h1 class="entry-title"> $theCondition is FALSE</h1>' );
}
?>
Function the_title(); may only return a string value in which case echo is required before the function.
John,
Thanks, but I couldn’t get it to work, it just rendered “The condition is FALSE” on the page.
I ended up writing a ‘display: none’ class as below:
<?php
if (is_front_page()) :
the_title( '<h1 class="hide-title">', '</h1>' );
else :
the_title( '<h1 class="entry-title">', '</h1>' );
endif;
?>
You can make it really short:
<?php !is_front_page() && the_title('<h1 class="entry-title">', '</h1>'); ?>
Pronounced as NOT is front page AND the title
That means the title will be shown only if it is not a front page
Awesome! even better!
Cheers megazoid.
I am not familiar with WordPress so hard-coded $theCondition=false;
which was missing in your original post and should have been is_front_page()
I am pleased you managed to get it to work.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.