WordPress.org

Ready to get started?Download WordPress

Forums

Custom Header Based on Page_ID? (3 posts)

  1. ebenjen
    Member
    Posted 7 years ago #

    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?

  2. ebenjen
    Member
    Posted 7 years ago #

    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?

  3. Doodlebee
    Member
    Posted 7 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic