Support » Plugins » Example of wrapping a custom header or footer around WordPress pages.

  • *NOTE: This only shows you how to call custom header or footer code to wrap your WordPress pages around. You still need to edit your theme to remove the default header or footer that comes with WordPress. Sidebars have not been considered as part of this solution*

    I spent a good couple of hours trying to work out, how to integrate WordPress into the current setup of my website. I have a basic site:- Front page (custom), Blog (WordPress, soon to be former Simple PHP Blog) and a Gallery (Coppermine).

    My header includes the Title of my Site, a lovely pic of me, and the navigation to the gallery or blog (and keywords in the code)
    The footer is just that, a picture of my feet.

    I didn’t want to use the delivered WP header or footer, because it did not match into my already existing website style. If I was starting off fresh, then maybe yes, the delivered H&Fs might have been perfect for integration with other packages. I just needed WordPress to fit between the two, to give consistency between the pages.

    My custom header.php and footer.php are in their own folder called ‘wrapper’, that sits in the root of my site where they can be called anytime from anywhere.

    To make sure WordPress called these two files, I edited the following file:
    wp-blog-header.php

    <?php
    /**
     * Loads the WordPress environment and template.
     *
     * @package WordPress
     */
    //This line calls the custom header.php file, before WordPress calls the template
    include ("../wrapper/header.php");
    
    if ( !isset($wp_did_header) ) {
    
    	$wp_did_header = true;
    
    	require_once( dirname(__FILE__) . '/wp-load.php' );
    
    	wp();
    
    	require_once( ABSPATH . WPINC . '/template-loader.php' );
    
    }
    //This line calls the custom footer.php file, after WordPress has called the template
    include ("../wrapper/footer.php");
    ?>

    Once you have this in place, you still need to edit the template files to remove the default delivered Header and Footer code. It may look ugly, but it works for me.

    I tried to use these support forms to find any existing solutions, but the ones I kept finding just didn’t match my requirements. I also found the level of support to be quite sneering of this type of request, as if by trying to have your own header or footer was offensive to those of the ‘Pure WordPress’ breed, that WP as delivered is perfect and requires no changes or hacks.

    If you don’t have an answer, don’t post. If your answer doesn’t match the poster’s requirements, don’t bitch about it. Everybody has their own idea on how their site should look, and this includes WordPress.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Seems like a great idea. It’s a common request around here to do this. Usually / often, the easier answer is to find a theme that you like, and modify the H&F that comes with it. But it sounds like you discovered a different workaround to use your own header. Cool.

    I read your tutorial. After that the thing I wanted is to see a live Demo, whether it is your site or a demonstration site.

    Thank you for posting your code. If you can show a Demo that would be even better. I am thinking about trying this.

    Plus you just gave me the idea of using a different PHP Include, even if I don’t replace the H&F, maybe I can create a file called “Visit All My Other Sites” that lists a few of my favorite links, and I can include this in all my sites’ themes so they would all link back to me & I could add another link to all my sites just by fixing the 1 included file.

    Thread Starter sidz

    (@sidz)

    Thanks Dgold, I love to see a bit of encouragement and enthusiasm.

    I can tell you now, I’m not much of a php coder. I can only just understand what I read, and can remove portions that are not required (ie when I get around to removing the default theme’s H&F for my own version of the theme).

    The below address is my DEV site for WP, that once I have finished my editing, will replace the blog that I currently have. I’m only testing WP to make sure it fits my requirements (which it does so far:- Email publishing and the iPhone app. Brilliant!!), but felt the need to pass on help to budding bloggers. I may not keep WP, but I sure need to move away from Simple PHP blog.

    http://blog2.sidz.id.au/

    sidz

    Thread Starter sidz

    (@sidz)

    I spent several hours editing the theme to match in with the colour and general overall look of my website, so I have decided to keep WP. BUT I need to now work out how to re-enable the RSS feed…

    My method above WILL BREAK YOUR RSS FEED or anything else that shouldn’t have code before it when the page gets generated.
    I am looking into a way for it to check the page before loading my custom Header and Footer. ie if the page is the RSS feed (or another page), do not load the custome H&F.

    I might even start to look at a way to remove my customised H&F and incorporate what I need back into the template itself, the way it really should be intended. But this would take away from what I was trying to accomplish. There is always another way to skin a wordpress!
    🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Example of wrapping a custom header or footer around WordPress pages.’ is closed to new replies.