• I have tried to change one of my pages to have a new header image.

    To do this I replaced <?php get_header(); ?> with <?php include (‘header2.php’); ?>

    The new header displays correctly at the top, however now a second old header is displaying after the footer. If I put <?php get_header(); ?> right after <?php include (‘header2.php’); ?> at the top of the page, the bottom header is removed, but now I obviously have two headers.

    The reason I am using a second header is to change a div and remove a search function in the “old” header code.

    Is there another way to go about making this change or editing the <?php get_header(); ?> Any help would be welcome.

Viewing 15 replies - 1 through 15 (of 18 total)
  • It sounds like you should be editing header.php and instead you are editing either index.php, single.php, page.php, or 404.php.

    I don’t quite understand your reason for doing this, but if you want the top section of one page to be different from the others, you can use conditional tags. If you just want to replace the original theme graphic entirely, save your new graphic with the same name as the old one and upload it over the original. If you want to get rid of the search box in your header.php just comment it out.

    Thread Starter skibybadoowap

    (@skibybadoowap)

    Here is the difference between the two header.php files:

    Original:

    </head>
    <body>

    <div id=”headerwrap”>
    <div id=”headerbg”>
    <div id=”header”>

    New Header:

    </head>
    <body>

    <div id=”headerwrap”>
    <div id=”headerbg2″>
    <div id=”header”>

    How would I go about making conditional tags for a page called “blogs.php” that resides in the same directory as index.php?

    I just corrected my original post because I assumed you were referring to the <?php wp_head(); ?> tag in the header.php. It seems to me like you should be editing header.php rather than index.php. Scroll up for more about that.

    Check the WP documentation for info about how to write conditional tags. Again, I’m not entirely sure what your goals are so it’s hard for me to advise you on how to get it done.

    Thread Starter skibybadoowap

    (@skibybadoowap)

    I have created an entirely new page called blogs.php. It’s in the same directory as index.php, footer.php, 404.php, ect. It and index.php share very similar code.

    When I have <?php get_header(); ?> at the top of the blogs page, it looks fine, but I want to editing the header of this new blogs page to look differently. To do this I have edited the style.css and header2.php files to get the look I want. (removing the search bar and changing the image)

    What I am looking for is a way to somehow get header.php to display normally on index.php and all other pages, but have blogs.php use header2.php.

    Sadly the conditional tag documentation seems to be related to “posts” not really “pages” in the way I am working with them.

    This code doesn’t seem to work:

    </head>
    <body>
    
    <div id="headerwrap">
    <?php if (is_blogs()) {<div id="headerbg2"> } else { ?>
    <div id="headerbg">
    <div id="header">

    What you need is a conditional tag like if (is_page in your header.php.

    <?php
      if (is_page("blog")) {
      echo '<div id="header" style="background:url(' .  get_bloginfo('url') . '/whateveryourpathis/yourimage.jpg) no-repeat bottom; ">';
      }  else {
       echo '<div id="header" style="background:url(' . get_bloginfo('url') . '/whateveryourpathis/yourOTHERimage.jpg) no-repeat bottom; ">';
      }
    ?>

    That would make a page called Blog have a different header graphic than all of your other pages. You could also add a similar bit of code to tell your theme which page(s) to show the search box on.

    You can also do arrays, but there is no point in me posting the code here because it’s available in the documentation.

    If you don’t want something to display at all on a certain page, use echo ' ';

    p.s. What I posted is just an example and may not work with your theme. What you have to do is look at how your theme is written and put your code in the echo ' '; line. That’s where you’re telling it what code to use for that page. You can also have multiple elseif statements in between the if and the else. Write them the same was as the if. The final else is the default code you want to use for pages or posts that don’t meet any of the above conditions.

    Thread Starter skibybadoowap

    (@skibybadoowap)

    I have used the code and the header image is displaying top-header.png on the blog page. It doesn’t seem to be picking up the is_page(“blog”) correctly. If I switch the if (is_page("blog")) to if (is_home()) it displays how I want on the homepage. The file is blog.php, is there something else that needs to be put in the is_page?

    <?php
      if (is_page("blog")) {
      echo '<div id="headerbg2" style="background:url(' .  get_bloginfo('url') . '/wp-content/themes/default/images/top-header2.png) no-repeat bottom; ">';
      }  else {
       echo '<div id="headerbg" style="background:url(' . get_bloginfo('url') . '/wp-content/themes/default/images/top-header.png) no-repeat bottom; ">';
      }
    ?>

    What is the name of the page that you are displaying your blog on? That’s what you want to put in the is_page("whatever"). You can also use the page ID#. This is all in the documentation, which you should read:

    https://codex.www.ads-software.com/Conditional_Tags

    Thread Starter skibybadoowap

    (@skibybadoowap)

    When I say “page” it isn’t a wordpress generated page, it’s a physical php page.

    In the root directory I made a file called blog.php with this code:

    <?php
    ini_set('display_errors','1');
    ini_set('display_startup_errors','1');
    error_reporting (E_ALL);
    define('WP_USE_THEMES', false);
    require('./wp-blog-header.php');
    require('wp-content/themes/default/blog.php');
    get_header();
    ?>

    This is normally the index code, except I renamed require('wp-content/themes/default/index.php'); to require('wp-content/themes/default/blog.php');.
    I then copied the index.php code of the theme I am using and renamed the file blog.php. This enabled me to go to https://www.mysite.com/blog and load up the file I wanted.

    The blog.php “page” is the one I am referring to in the previous posts. I think is_page("whatever") would work, if the “page” was an actual wordpress generated page. I think I’m more looking for something like editing a method like is_home() or is_404() to is_blog(). Any ideas how to do this?

    I’m not sure why you want to “break out of the box” and create a complete page in an external document. It seems like even if you wanted a page that displayed completely differently from your others you would create a page template and use that within a “normal” WordPress page, and/or use conditional tags to make different pieces of code appear on different pages. I’ve used both for various reasons and they both work well.

    The reason you can’t write a “header2.php” or something like that so easily is because you don’t have a function to get that document. For example, things like get_header, get_sidebar, etc. are functions that are defined in your theme. get_header2 is not. So, you can’t even use is_page to replace the function with a call to a new function because the new function is not defined. OTOH if you created a function that said header2 gets this new file of yours, then it would work. Seems like what you really want to do is display a modified header.php on a certain page. You can do that w/ conditional tags. To me that seems like the easier way to do it.

    So what if where your theme normally says <?php get_header(); ?> you change it to say if is_page("your-page-name-or-id") and then echo 'your whole block of code that you have in this other document';, and then else { echo '<?php get_header(); ?>'; }

    ?

    or if (is_page("your-page-name-or-id")) then echo '<?php include ('header2.php'); ?>'; , and then else { echo '<?php get_header(); ?>'; }

    and BTW I think you may need to make that change in page.php rather than index.php.

    Also, I am not testing any of this code, so use at your own risk. Make backups before you change anything in a working page/site.

    Thread Starter skibybadoowap

    (@skibybadoowap)

    Do you know how I would make a header2 function that would work? I have all the other pieces in place if I can get that working.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘<?php get_header(); ?> Displaying at the bottom’ is closed to new replies.