• Resolved eludlow

    (@eludlow)


    Hi there.

    I’d like to set up my Twenty Twelve theme to show the header image only on the homepage. Before updating to the latest version of the theme, I could sort this by replacing, in header.php, the following line:

    if ( ! empty( $header_image ) ) : ?>

    with

    if ( ! empty( $header_image ) && is_home() ) : ?>

    But this now removes the header from all pages.

    Can anyone advise why this isn’t working? As far as I can see the conditional tag is being used as it should be.

    Many thanks in advance,
    Ed

Viewing 6 replies - 1 through 6 (of 6 total)
  • Can you post a link to your site please. I’ll be able to see what template is loading for the homepage and advise accordingly.

    Thanks,

    Afzaal

    Thread Starter eludlow

    (@eludlow)

    I’m a little stumped. It seems that your homepage is using a template file. Try disabling this if you can. Alternatively this is the fix that I use as is_home() can be a bit fiddly at times:

    Add the following code to your themes functions.php file:

    function custom_home() {
    	$pageURL = 'http';
    	if( isset($_SERVER["HTTPS"]) ) {
    		if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    	}
    	$pageURL .= "://";
    	if ($_SERVER["SERVER_PORT"] != "80") {
    		$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    	} else {
    		$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    	}
    	return $pageURL;
    }

    Now change your code to be the following:

    if ( ! empty( $header_image ) and ( is_home() or site_url( '/' ) == custom_home() ) ) : ?>

    Essentially we’ve added another check for the homepage. Hope this helps.

    Afzaal

    Thread Starter eludlow

    (@eludlow)

    Fantastic, thank you VERY much!

    Ed

    Hi,
    I’d like to set up my Twenty Twelve theme to show the header image only on the homepage. I don’t understand where is the right point to add the code and where to change.

    Thank you very much.

    The site (twenty twelve theme) is:
    https://www.lucabrunoro.it

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Twenty Twelve – header image on homepage only’ is closed to new replies.