WordPress.org

Support

Support » How-To and Troubleshooting » Custom Header Based on Page_ID?

Custom Header Based on Page_ID?

  • Is there a way to have a different header image on each page according to the page id? For example, the file ‘header.php’ includes the following code to determine what header image to display

    <?php } elseif (is_page()) { ?>
    <img src="<?php bloginfo('template_url'); ?>/images/header_3.jpg" width="770" height="140" alt="<?php bloginfo('name'); ?> header image 3" title="<?php bloginfo('name'); ?> header image 3" />

    This puts the image, ‘header_3.jpg’ on every page that uses the page template. What I’d like to do is have the header image chosen based on page_id instead like this…

    <?php } elseif (is_page_id=3()) { ?>
    <img src="<?php bloginfo('template_url'); ?>/images/header_3.jpg" width="770" height="140" alt="<?php bloginfo('name'); ?> header image 3" title="<?php bloginfo('name'); ?> header image 3" />
    <?php } elseif (is_page_id=4()) { ?>
    <img src="<?php bloginfo('template_url'); ?>/images/header_4.jpg" width="770" height="140" alt="<?php bloginfo('name'); ?> header image 4" title="<?php bloginfo('name'); ?> header image 4" />

    Will that work or is there another way to code it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • No reply so I tried it and discovered that it won’t work. I then tried this:

    <?php } elseif (is_page('page_id=1')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/images/header_1.jpg" width="770" height="140" alt="<?php bloginfo('name'); ?> header image 1" title="<?php bloginfo('name'); ?> header image 3" />
    <?php } elseif (is_page('page_id=2')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/images/header_2.jpg" width="770" height="140" alt="<?php bloginfo('name'); ?> header image 2" title="<?php bloginfo('name'); ?> header image 3" />
    <?php } elseif (is_page('page_id=3')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/images/header_3.jpg" width="770" height="140" alt="<?php bloginfo('name'); ?> header image 3" title="<?php bloginfo('name'); ?> header image 3" />
    <?php } elseif (is_page('page_id=4')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/images/header_4.jpg" width="770" height="140" alt="<?php bloginfo('name'); ?> header image 4" title="<?php bloginfo('name'); ?> header image 3" />
    <?php } elseif (is_page('page_id=5')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/images/header_5.jpg" width="770" height="140" alt="<?php bloginfo('name'); ?> header image 5" title="<?php bloginfo('name'); ?> header image 3" />

    and that doesn’t work either.

    Is there any way to have a custom header image depending on page_id?

    Anybody?

    Doodlebee
    Member

    @doodlebee

    I just posted on my old Dynamic Stylesheet thread – it’s only a few posts down from this one.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Header Based on Page_ID?’ is closed to new replies.