WordPress.org

Ready to get started?Download WordPress

Forums

Spun
[resolved] help using is_front_page (10 posts)

  1. Bastienne
    Member
    Posted 1 year ago #

    Hello guys, I'm totally new at php so here's a straightforward question:

    I am trying to hide some things on my static home page, the site title and the navigation bar and the footer/colofon. I think I should use the php conditional tag is_front_page for this, like so:

    <?php if( is_front_page() ) { ?>
    do something
    <?php } ?>

    But:

    - Where do I put this code? in the header.php and footer.php? or in the style.css? At which location in those files?
    - What exactly do I put in the place of 'do something' is it css code? What is the syntax?

    Thanks,
    Bastienne

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    First make a Child Theme.

  3. Bastienne
    Member
    Posted 1 year ago #

    I do have a child theme already

  4. Andrew
    Forum Moderator
    Posted 1 year ago #

    Copy header.php from your theme and paste it into your Child Theme.

  5. Bastienne
    Member
    Posted 1 year ago #

    yep got it

  6. Andrew
    Forum Moderator
    Posted 1 year ago #

    In your Child Theme header.php file, wrap that conditional tag around the title and navigation:

    <hgroup>
    			<h1 class="site-title"><a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
    		</hgroup>
    
    		<nav role="navigation" class="site-navigation main-navigation">
    			<h1 class="assistive-text"><?php _e( 'Menu', 'spun' ); ?></h1>
    			<div class="assistive-text skip-link"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'spun' ); ?>"><?php _e( 'Skip to content', 'spun' ); ?></a></div>
    
    			<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
    		</nav><!-- .site-navigation .main-navigation -->

    But use the exclamation mark in the conditional tag to say "if not", rather than "if".

    <?php if( !is_front_page() ) { ?>
    <hgroup>
    			<h1 class="site-title"><a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
    		</hgroup>
    
    		<nav role="navigation" class="site-navigation main-navigation">
    			<h1 class="assistive-text"><?php _e( 'Menu', 'spun' ); ?></h1>
    			<div class="assistive-text skip-link"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'spun' ); ?>"><?php _e( 'Skip to content', 'spun' ); ?></a></div>
    
    			<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
    		</nav><!-- .site-navigation .main-navigation -->
    <?php } ?>
  7. Bastienne
    Member
    Posted 1 year ago #

    yes great!

    And now I can do the same for the footer?
    and if I want to hide the background image on the front page, where is this located?

    thanks very much for your direct online help!

  8. Bastienne
    Member
    Posted 1 year ago #

    btw is it now better to remove any other code from the header.php, so as not to interfere with any updates that the original theme makes?

    If so, what should I delete and what not?

  9. Andrew
    Forum Moderator
    Posted 1 year ago #

    And now I can do the same for the footer?

    Yep.

    and if I want to hide the background image on the front page, where is this located?

    You'll have to create a CSS style for this, in your Child Theme style.css file.

    E.g:

    body.home {
     background: none;
    }

    btw is it now better to remove any other code from the header.php, so as not to interfere with any updates that the original theme makes?

    Nope it is not better that way. Your Child Theme doesn't just override particular code that you've changed in header.php, it overrides the whole header.php file.

  10. Bastienne
    Member
    Posted 1 year ago #

    I'm pretty terrible at css too, I must admit.
    When I have created the style, then what?
    thanks again...

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic