user3506938 user3506938 - 1 month ago 5
PHP Question

How to make header show only on home page? Wordpress

Here is the website I am editing with wordpress:

www.thestudentbubble.com

As you can see there is a 'header' the 3 lines explaining what the site is about.
How do I makke this appear only on the Home Page?

I found the Header.php file and the code looks like this currently:

<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img src="<?php header_image(); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" /></a>
<?php endif; ?>

Answer

Try this:

<?php
if ( is_home() ) {
    // This is a homepage
} else {
    // This is not a homepage
}
?>

Wordpress is_home() function. You can also use is_frontpage()

<?php
if ( is_front_page() ) {
    // This is a homepage
} else {
    // This is not a homepage
}
?>

Little more information on what is difference between these:

if ( is_front_page() && is_home() ) {
  // Default homepage
} elseif ( is_front_page() ) {
  // static homepage
} elseif ( is_home() ) {
  // blog page
} else {
  //everyting else
}