• Resolved dancigers

    (@dancigers)


    Hi all,
    I am trying to hide the header “h1” in my static front page only. Is there a way to do this is the CSS or do I need to edit the Header php? I’m using the “modern” theme, and the header php appears blank. Any help would be hugely appreciated.

Viewing 14 replies - 1 through 14 (of 14 total)
  • You can use CSS to make it not display – find the body class of the homepage and do something like:

    .home h1 {
      display: none;
    }

    This is only a solution if you are not using any other h1 tags on the homepage, and may also have negative SEO side effects, as it may be perceived by search engines as gaming.

    Instead, I recommend editing page.php – or whatever other template file is being applied to your homepage.

    Find where the h1 tag is being called, and do something like:

    <?php if (!is_home()): ?>
    
    your h1 line goes here
    
    <?php endif; ?>

    What this code does is says – if the page is not the homepage, then display the h1 heading.

    Reference: WordPress Conditional Tags

    Thread Starter dancigers

    (@dancigers)

    Great, thanks so much for the reply. I will try to PHP code solution: using that code in the CSS, the H1 header doesn’t display on all pages. Will report back with results…

    using that code in the CSS, the H1 header doesn’t display on all pages.

    You would need to check the actual body class on your homepage and find the class that only applies there. The code I gave you was just an example – I’d need to see your site to help further.

    Thread Starter dancigers

    (@dancigers)

    Zoonini,
    Couldn’t quite figure out what to put in the “h1 line goes here” part of the code. Here is the code to my page.php. Seems to be the only template file at work; the header.php is blank.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thanks again for any help!

    Thread Starter dancigers

    (@dancigers)

    If helpful, the site is https://markdancigers.com.

    Ah – can you post the contents of whatever file is generating the top part of your code into a pastebin? Normally that’s header.php but you say it’s blank?

    You are also missing the class assignments on your <body> tag, which is why the CSS method didn’t work. In header.php change <body> to <body <?php body_class(); ?>> to get that working.

    What template file are you using for your static homepage – the h1 tag might be there. Did you create a custom template or are you using a home.php template? If so, put the contents of that file in a pastebin so folks can take a look.

    Thread Starter dancigers

    (@dancigers)

    I’m just using the wordpress option to use a static page as the homepage, no special templates… As far as I can tell, the only thing generating the h1 tag is the CSS sheet. I’m using the Modern theme and this theme comes with no home.php and the header.php is blank. There is a page.php, which is pasted above. I’ll paste the css into a pastebin…
    https://pastebin.com/u/brucemadbox
    hope this helps, and thanks again.

    Thread Starter dancigers

    (@dancigers)

    And here is the page.php code:
    https://pastebin.com/u/brucemadbox

    header.php of the ‘modern’ theme – fresh download:

    https://pastebin.com/UFE8Lbh4

    Thanks alchymyth.

    So here’s the line with your h1, from header.php:

    <h1><a href="<?php echo get_settings('home'); ?>"><?php bloginfo('name'); ?></a></h1>

    I’m not sure why yours is blank, unless you edited it. In any case, the h1 has to be coming from somewhere.

    Thread Starter dancigers

    (@dancigers)

    OK, thanks so much! VERY close now. using this:

    <?php if (!is_home()): ?>
    
    your h1 line goes here
    
    <?php endif; ?>

    the h1 does not display on my Blog page. However, I’d like this feature on my static front page rather than the blog page (I guess in the code “home” is still the blog). In the above code, how should I re-name the “home” part to indicate my static front page?

    Thread Starter dancigers

    (@dancigers)

    Changed it to front_page and it worked! Zoonini and Alchymth, thank you very much!

    Awesome!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘How to hide the header h1 in only my front page?’ is closed to new replies.