• Hi,

    I used the method described here to get a different header image depending on what page a visitor is on.

    My page is here.

    I think it is working, but there are broken image icons on top of the default header images. I am not sure if my image path is wrong (I’m sure that it is correct though) or if I have missed something in integrating it into the page.

    Below is the code for header.php:

    <?php
    /**
     * @package WordPress
     * @subpackage Default_Theme
     */
    ?>
    <?php
    if(is_page('2')){
    echo '<images/header-about.jpg" />';
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="https://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    
    <head profile="https://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    
    <title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
    
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    
    <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
    
    <?php wp_head(); ?>
    </head>
    <body <?php body_class(); ?>>
    <div id="wrapper">
      <div id="small_slide"><img src="images/small_slide.png" width="431" height="249" /></div>
      <div id="header"><img src="images/header.jpg" width="899" height="283" /></div>

    Can anyone see something noticeably wrong?

Viewing 7 replies - 1 through 7 (of 7 total)
  • <div id="header"><img src="images/header.jpg" width="899" height="283" /></div>

    try

    <div id="header"> <img src="<?php bloginfo('template_url'); ?>/images/header.jpg" width="899" height="283" /></div>

    Thread Starter Diventare Creative

    (@wms-group)

    Okay, that worked… I did the same for the small_slide.jpg image and that was the trick. NOW, my page is actually supposed to bring in header-about.jpg as referenced in

    ?>
    <?php
    if(is_page('2')){
    echo '<images/header-about.jpg" />';
    }
    ?>

    but that doesn’t seem to be working.

    should that bit of code be up in the <head></head> area of your template where it is now?

    Or down somewhere after the <body> opening?

    The problem is this code.

    <?php
    if(is_page('2')){
    echo '<images/header-about.jpg" />';
    }
    ?>

    All this is going to do is at the top of the header.php in the source code is put <images/header-about.jpg" />. I think I see what your trying to do. Try out this code.

    <?php
    /**
     * @package WordPress
     * @subpackage Default_Theme
     */
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="https://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    
    <head profile="https://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    
    <title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
    
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    
    <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
    
    <?php wp_head(); ?>
    </head>
    <body <?php body_class(); ?>>
    <div id="wrapper">
      <div id="small_slide"><img src="<?php bloginfo('template_url'); ?>/images/small_slide.png" width="431" height="249" /></div>
      <div id="header">
    <img src="<?php bloginfo('template_url');
    if(is_page('2')) {
    echo '/images/header-about.jpg'; }
    else { echo '/images/header.jpg'; } ?>" width="899" height="283" /></div>
    Thread Starter Diventare Creative

    (@wms-group)

    jermyclark13, thank you, that fixed it! Now was RVoodoo right in saying that it was placed incorrectly? Looks like you moved it down inside the “header” div.

    Yes like I said all the code was doing was simpling echoing out the code where it’s placed. I just edited the code a little to have an else statement that when the if statement was true it would fall back to the default.

    Thread Starter Diventare Creative

    (@wms-group)

    Great, I get it now. Thank you for your help ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Conditional tags in header.php code for custom header on pages’ is closed to new replies.