I’ve done several posts about Thesis headers before: Thesis full-width headers, Full-width headers in Thesis 1.5 and CSS Custom Headers.
All of those lead you in the same general direction: a single custom header for your blog. I recently got asked for step-by-step instructions on how to specify different headers on specific pages. So, I’m going to show you two ways to achieve that: CSS image replacement and inline header images.
CSS image replacement
The simplest way to customise your header (in my opinion) is to use a background image. There are several permutations of the CSS1 that will achieve such a thing, but the bare minimum would be something like the following.
.custom #header {background:url(images/header.jpg) center top no-repeat; height:150px; padding:0 1.1em;}
.custom #header #logo a {display:block; height:150px; text-indent:-9999px;}
If header.jpg is in your custom/images folder and you’ve unchecked the option to display the tagline on the Thesis Options page, the above CSS will give you a clickable header that looks like…
This will be the header for every page that we don’t specifically change.
Page specific body class
Thesis provides body classes for all the pages in your WordPress site. You can also provide your own body class to any page or post by filling in the relevant field when writing a post. On top of all that you can filter the body class via a custom function to add a body class to any page accessible via conditional tags.
Page specific header
Using the page specific body classes, we can give individual pages their own CSS header. All you need to do is use .page-name instead of .custom.
Assuming the new image is the same height as the default one, the CSS to give your About page a unique header is…
.about #header {background:url(images/header_about.jpg) center top no-repeat;}
Adding body classes
You can keep adding unique headers across your site to your heart’s content… If the page you want to target doesn’t already have a unique body class you can give it one with the following function.
function custom_body_classes($classes) {
if (is_home())
$classes[] = "home";
if (is_category())
$classes[] = "category";
return $classes;
}
add_filter('thesis_body_classes','custom_body_classes');
This function (placed in custom_functions.php) specifies the pages to target using conditional tags, and then adds the desired classes to an array called $classes, which is filtered back through the Thesis function that outputs the body classes2. Using this we could give the same header to all the category archive pages (with is_category()), or all the posts in a specific category (with in_category('Fancy Headers') and so on.
CSS summary
All of the CSS put together might look like the following.
.custom #header {background:url(images/header.jpg) center top no-repeat; height:150px; padding:0 1.1em;}
.about #header {background:url(images/header_about.jpg) center top no-repeat;}
.archives #header {background:url(images/header_archives.jpg) center top no-repeat;}
.category #header {background:url(images/header_category.jpg) center top no-repeat;}
.custom #header #logo a {display:block; height:150px; text-indent:-9999px;}
Inline header images
Alternatively, we can use PHP and HTML instead of CSS to replace the contents of the header.
The whole function that goes in custom_functions.php is,
function custom_header() {
// header for About page
if ( is_page('About') )
echo '<p id="logo"><a href="' . get_bloginfo('url') . '"><img src="' . THESIS_CUSTOM_FOLDER . '"/images/header_about.jpg" alt="' . get_bloginfo('name') . '" /></a></p>';
// header for Photos category pages
elseif ( is_category('Photos') )
echo '<p id="logo"><a href="' . get_bloginfo('url') . '"><img src="' . THESIS_CUSTOM_FOLDER . '"/images/header_purple.jpg" alt="' . get_bloginfo('name') . '" /></a></p>';
// header for posts in Tutorials Category
elseif ( in_category('Tutorials') )
echo '<p id="logo"><a href="' . get_bloginfo('url') . '"><img src="' . THESIS_CUSTOM_FOLDER . '"/images/header_tutorials.jpg" alt="' . get_bloginfo('name') . '" /></a></p>';
// header for all other pages
else
echo '<p id="logo"><a href="' . get_bloginfo('url') . '"><img src="' . THESIS_CUSTOM_FOLDER . '"/images/header.jpg" alt="' . get_bloginfo('name') . '" /></a></p>';
}
remove_action('thesis_hook_header', 'thesis_default_header');
add_action('thesis_hook_header', 'custom_header');
Understanding the function
- The only parts that need changing are the conditional tags and the image names.
- There is a list of conditional tags in the WordPress Codex that can be used in this function.
- In the HTML markup for the header I’ve included
<p id="logo">to match the default Thesis markup. get_bloginfo('url')is PHP and fetches the URL of your blog.get_bloginfo('name')is PHP and gets the name of your blog. This is important as the alternative text for the image; if the image doesn’t load for any reason the alternative text will be shown and since we wrapped the image with<p id="logo">it will be formatted correctly as the blog title.remove_action('thesis_hook_header', 'thesis_default_header');removes the default markup of the Thesis header so that we can add our own content into the header.
If you want to insert this code using the Thesis OpenHook plugin, make sure that you convert the function properly and don’t forget <?php ?> tags around the conditional tags.
Best of luck and feel free to ask questions in the comments below!
- If you want more info on basic CSS elements and syntax, have a look at the Tizag CSS tutorial [↩]
- For more about PHP syntax and operations check out the Tizag PHP tutorial [↩]
↓






{ 52 comments… read them below or add one }
This is WONDERFUL. Thank you!
Could you maybe share a note about how to size/create your own header to begin?
Thank you again for your sharing.
T
Kristarella,
This works for me. I used the CSS Image Replacement method. Thanks again so much!
John
Thank you for yet another wonderful tutorial. One of the things I really like about visiting here each day, is I not only find out something new I can do to my site, but how to do it. Very well done!
Kris – You always do such a good job with your tutorials. I still go back and re-read some of your earlier one’s here and on the Thesis forums whenever I need a refresher. Another job well done!
Chris
Kris – another useful post. Thanks for sharing.
I have problems in making my Thesis header image clickable (URL will be my blog url). Can you help me out? You can visit my blog – I am providing it in the website link.
Thanks
Ashwin — you need the CSS
.custom #header #logo a {display:block;}(because by using a negative text indent there is no text to fill out the inline anchor element in the header).Kris – that worked well. Thanks for the tip.
I follow a lot of your tutorials. Would be great if you can give me some feedback about my blog design using Thesis. Thanks for your time.
Regards,
Ashwin
Hey Kristarella – Over the past week, I’ve read your blog posts on custom header so many times, I feel like we know each other.
I’m waiting for the penny to drop via experimentation. Backing Tom up – creating the headers in Photoshop – is there any particular size I should be sticking to? I’m thinking a similar size and layout to surgarae’s header with the background all the way to the top.
I’m using Firebug to see whats going on there but I’m stumbling around in the dark still. It will come.
Thanks again so much for the time you have taken to write these posts.
Mark
Tom & Mark — Since users can make their Thesis site absolutely any size they want it’s impossible to say what size your image should be, except that Mark has the right idea with using Firebug.
I have a video about using Firebug and you can also use Webkit Inspector if you’re in Safari or Chrome. By clicking on “Layout” in Firebug or “Computed Styles” in the Webkit Inspector you can determine how wide in pixels your header is. I think in a default install of Thesis the header is 927px wide plus 11px of padding on each side, so your header should be 949px wide.
You can use whatever height you want. I used 150px, Sugarrae’s is 215px including the red line below it (although the image is slightly wider than the header actually is).
Thanks for the prompt reply Kristarella,
That video tutorial was off the ricta!
I get it now – sorta. In firebug – I checked the layout tab, inspected my header (and sugarae’s – firebug is borderline creepy) and the layout told me exact sizes. No more use for the Measurit addon.
My header area is 1664 x 189. Should I just create my photoshop logo that size. Or can I easily adjust the dimensions of my header area?
Last question – is Sugarrea using a full width header? I notice her background appears on both sides of her logo. I like it.
Promise I won’t hassle you any more. :-)
Mark
OK – update – your video on Full Width Framework just answered my ‘last question’
Thank you so Much Kris.
Tom
Mark — glad the full-width video helped, but I’m not really sure about your first question.
#header_areawill be however big your browser is, so I would recommend a solid colour or a repeating image or texture for that. The main content part of your header with title etc needs to be the width of#headeror smaller, otherwise people using smaller monitors won’t be able to see all of it.Hope that helps!
When building a custom header for a thesis theme is the best size 900 by 150? Or is there another size that works better.
Thanks
Terry
Terry — Please see the comment above regarding image sizes. Thanks :-)
Kristarella,
You are a genius. I have been struggling with this for 2 days. What a simple solution!
Hi Kristella,
Thaks for this. I have been pulling my hair out all day trying to customise my headers. Just a quick question. I have made my home page a static page and put my posts on my blog page. when i use your css route above and use .blog #header … it picks up the .customer #header. Do you have a suggestion on how i can fix this??
Thanks
Michael
Michael — Every page will always have the “custom” class assigned to the body and certain pages will have additional classes assigned.
.customand.homealways have the same importance because they are both only classes, so the only way to override a style on the same element is to put it after the other style in the style sheet. So you should put all your default custom styles first and then specialised page styles later in custom.css.Thanks so much Kristarella. Really appreciate the help.
Hi Kristella,
First of all, your website is fantastic. I learned a lot from it.
However, I had a question, which I’m sure is very simple for you to answer.
Is there a way I can have my content container be white whereas my entire site background be the same color as my footer (#444444)? I have been struggling to figure this out for several hours now, but haven’t been able to find a solution.
I hope you will be able to help me.
Thanks in advance. – Anshoo
I forgot to mention that, I have been successful in doing so with both Firefox and Chrome, but I haven’t been able to figure out how I can implement this with IE 6. Most of my user-base uses IE6.. :(
Anshoo — It is not working 100% in IE6 because IE6 hates negative margins. You would be much better off using the full-width framework.
Hi Kristarella, I played around nearly the entire day today and all of last night.. and was able to figure out the reason. I’m 99% done :)
Just one question though, if you see the website, the border above the copyright stretches all the way across the screen (in FF). Is there a fix for that? IE is nearly done, too. GodHammer and DiyThemes helped me out a lot :)
Thank you :)
Ansho0 — The width of that section is 97%. Try making it 97.4em like the page container.
Thank you so much Kristarella! Its finally fixed now.
:)
Kristarella, thanks to you, I think this is the first time I like the way my website is looking now.
Hello Kristarella,
I’m trying to add a page specific header within my site.
I used the code for page specific header in my custom.css
.test #header {background:url(images/VS1CROPR.jpg) center top no-repeat;}
the image gets pulled, but it sits behind the default flash header for the rest of the site. Therefore you don’t see it because the flash header still runs on the page.
If you reload the page you will see the page specific header for a split second. So it is there, but behind the default header.
Do you know how I can fix this?
Thank you!!!
Khan — Since the flash header is probably added as HTML via PHP you will need to add an exception in the PHP in the form of a conditional tag. E.g.
if (!is_page('Test')) { FLASH CODE }.Kristarella,
Thank you for the advice, I haven’t tried it as I’m just reading this now.
I solved the issue by using Dynamic Header Plugin
http://wordpress.org/extend/plugins/dynamic-headers/
Worked out okay with a bit of tweaking.
Thanks for the post and the great article.
Khan
In ‘Inline header images’ section where you have ” . THESIS_CUSTOM_FOLDER . ” in the code, is that to be replaced with a path?
I want to use this in Openhook since I already have it displaying rotating random images on pages, but I want to use a specific image on a few special pages. Trying this, I get the alt text – the site title and not the image, so I’m not getting the path to the image right.
Thanks
Joel — It does not need to be replaced as long as you are echoing with PHP because
THESIS_CUSTOM_FOLDERis a defined path in PHP for Thesis. If you’re using OpenHook and no longer echoing the URLs, but using plain HTML then you do need to edit the path so that it goes fromsrc="' . THESIS_CUSTOM_FOLDER . '"/images/header_purple.jpg"tosrc="http://www.example.com/wp-content/themes/thesis/custom/images/header_purple.jpg".I feel like an idiot! But I cannot get a header image to show on http://earthadvertising.com/blog.
I’ve put the EAheader.jpg in both the images file and the thesis/custom/images file; but it can’t seem to find it. You can see my css on this blog page. Here’s what I put in the Custom File Editor:
.custom #header {border-bottom:none; height:112px; background:url(images/EAheader.jpg) center left no-repeat; padding-top:0; padding-bottom:0; }
/* .custom #header #logo {display:none;} */
.custom #header #tagline {display:none;}
(I temporarily hid the .custom #header #logo info, because I had to have SOMEthing up there!)
Please help! I’m new to Thesis, and it seems rather awkward so far.
Many thanks!
— Nancy
Thanx for the great Thesis article. Came here through search and just couldn’t stop reading. Very good blog :-)
Nancy — Looks like you’ve changed the whole theme over. Sorry, can’t help if I can’t see the issue.
Hi Kristarella,
I used your CSS code for a custom header and also the one so I can have different headers on individual pages. On Internet explorer it works perfect, but on google chrome and firefox my headers do not show at all. Do you maybe know of a reason for this, and maybe a possible solution? Did I pherhaps do something wrong?
thank you so much
Claudia — It’s not a good idea to have file names with spaces in them. Try changing your image file names to have hyphens or underscores instead of hyphens. I don’t know if it makes any difference, but Thesis doesn’t need to be in an extra folder, you seem to have themes/thesis_16/thesis_16 All the theme files can just be in the first thesis_16 folder, it doesn’t need to be two-tiered, but it might not make a difference, I’m not sure.
Hi,
I removed all spaces from my file name and that did the trick. Thank you so much. I realy appriciate your advise and help. Your posts are a great support. thank you!!!!
The articles you have provided above is really helpful and really useful for the Thesis Theme lovers. I would like to decorate my blogs header by the way you said. Good works kristarella.
What would I do if I want to make the after_header image to show only on the homepage?
Michelle — It depends how you have added it. If you’ve added it as HTML in a function, you wrap it in a conditional like this, if it’s a CSS thing you use a body class.
I studied the css tutorial and I really learned a lot. I think my next homepage will be a lot better than my first one.
Thanks very much for this tutorial. I am doing a lot of customisation on a clients site and they wanted a page with no navigation in the header which freaked me out initially. I used the inline header method and can specifiy exactly which pages will have the different header now – yay : )
Thank you–tried a whole bunch of solutions to this, and this was by far the most elegant. Appreciate it!
Can you please let me know how can I put the menu bar at the header height. For example I have my logo at the header to the left side of the page but I want to put the menu to the right side of the logo but at the same height as the header. What would the be to acquire that? Thanks in advance
Tony — Take a look at the menu CSS for my mini skin, which has the menu in line with the header. I may have to write a tutorial for it because I get a lot of questions about how to do it.
I have followed your tutorial, which all of them are great by the way, and I have run into a little tiny problem. I used the CSS way, giving each page a unique class and adding the different header via CSS, it seems that this works, going to about shows the about image, and going to contact shows contact, but it makes my menu disappear when I have the code (remove_action(‘thesis_hook_before_header’, ‘thesis_nav_menu’);
add_action(‘thesis_hook_after_header’, ‘thesis_nav_menu’); ) in my functions.php from a different tutorial on your site to make the navigation below the header. I would like my navigation to essentially float on top of this background header that I am trying to use. I thought using the function edits I pasted here would allow both things I want to work, but when adding this unique header, it causes the menu to disappear, but without it, my nav is on top of my header and will not overlap the image. Any suggestions? Thanks in advance!
Bhorton — CSS header images shouldn’t affect the navigation in anyway, unless there’s an error in your custom_functions.php file before the nav code that’s preventing it to execute. Perhaps If you paste your file at Pastebin and give the link, I might be able to see if that’s the case.
Or, you might just need to use
thesis_hook_after_titleinstead ofthesis_hook_after_headerbecause the latter doesn’t put the nav inside the header element and would therefore be below any image you have in#header.Using the thesis_hook_after_title rather than header worked and allowed me to put the navigation on top of the header, and it is still there on the other pages now! Thank you. – You do great work!
Hi Kristarella,
I want to to overlay about 20px of my header image onto Content. Cuz there is a little image that should present on the content which originally is a part of Header. Is there anyway to do that?
Thank you,
Josh
Joshua — It depends a bit on which framework you’re using etc, but you can probably achieve something like that with positioning. E.g.,
position:relative; top:-20px;to move something up on the page by 20px. You might also need to addz-indexto some elements to get them to overlap in the right order.I’ve got a bit more info about CSS position in my position nav tutorial.
I’m building a Thesis site with a lot of static pages, most with at least one level of subpage. I would like to have a separate header for each of these “sections,” or top level pages and the pages below it, and have the header appear automatically for each section – without the subpage creator having to do anything special. Is this possible?
Thanks for all your great tutorials.
Adam — Yes, you can use either method in this post to add the headers. Use the conditional tag
is_page()to target the pages and a custom function to target the subpages. Details for that functions are on the conditional tags Codex page.