• Resolved Bastienne

    (@bastienne)


    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

Viewing 9 replies - 1 through 9 (of 9 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    First make a Child Theme.

    Thread Starter Bastienne

    (@bastienne)

    I do have a child theme already

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

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

    Thread Starter Bastienne

    (@bastienne)

    yep got it

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    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 } ?>

    Thread Starter Bastienne

    (@bastienne)

    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!

    Thread Starter Bastienne

    (@bastienne)

    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?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    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.

    Thread Starter Bastienne

    (@bastienne)

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

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘help using is_front_page’ is closed to new replies.