WordPress.org

Forums

[resolved] [closed] Twenty Twelve - header image on homepage only (7 posts)

  1. eludlow
    Member
    Posted 2 years ago #

    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

  2. ThinkUpThemes
    Member
    Posted 2 years ago #

    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

  3. eludlow
    Member
    Posted 2 years ago #

  4. ThinkUpThemes
    Member
    Posted 2 years ago #

    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

  5. eludlow
    Member
    Posted 2 years ago #

    Fantastic, thank you VERY much!

    Ed

  6. Ellebi
    Member
    Posted 1 year ago #

    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:
    http://www.lucabrunoro.it

  7. Andrew Nevins
    Forum moderator
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic