free hit counters
If you are using Internet Explorer as your browser please be running at least IE 7 or above. This site does not support IE 6 or below. Go here for the latest free version including easy download and installation instructions If you want to make it real easy on yourself, download Firefox , the most popular browser in the world. It's free and simple. You'll be so glad you did.
Nov
10
2008

How to add your own custom header with hooks

To put your own image or header image in the “header location”, its a really simple matter of writing a function. The function makes it easy to upload the image. It’s a lot easier when you upgrade as well.

Make sure your image is in your custom/images folder.

In your custom_functions.php file add the following code. You can put it anywhere you want but I recommend putting it at the top after the <?php tag. Always describe the function and put it between the comment tags /*  */ at the beginning shown below in green. The comments aren’t shown on your rendered page and it just makes things easier for you to remember…

/*custom header image*/
function mycustomheader () { ?>
<div id =”headername” ><img src=”<?php bloginfo(’template_directory’) ?>/custom/images/myheader.png” alt=”  ” />
</div>
<?php }
remove_action ( ‘thesis_hook_header’,'thesis_default_header’);
add_action (’thesis_hook_header’, ‘mycustomheader’);

Name your custom function. I used “mycustomheader” just for an example.

Wrap it in a div tag, give it an id or class name whatever you want. That way you can style it in the custom.css with the name of “.headername” or “#headername”.  Name it whatever you want.

Check out the php code in the img src. It makes it a lot easier than having to type the entire path.

You have to “un-hook” the default header first. That’s what the “remove_action” does.

Add your image in your header area with the add_action ‘thesis_hook_header’ and hang your “mycustomheader” on it.

Leaving a comment with code in it...

If you would like to leave a comment and you have examples of code you want to show, you must "escape the code". This allows the entire code to show correctly by inserting certain variable around certain tags to make them show. If you don't "escape the code" your code will show up broken, mangled, and it won't be able to be seen correctly. "Escaping the code" is very simple...

  1. Copy your code you want to show
  2. Click here to go to the site to escape the code
  3. Follow the directions, it's so easy
  4. Once you have the escaped code copied, paste it in the comments area where you want
  5. Now you can enjoy life


Go ahead, leave a comment...

{ 7 comments… read them below or add one }

Anthony March 3, 2009 at 2:50 pm

I am using this code for my header:
function add_header_image () {
echo “

“; }
add_action(’thesis_hook_before_title’, ‘add_header_image’);

For some reason the I cant put my nav bar below the header. Is it because of the action at the bottom?

Reply

Nasty March 4, 2009 at 7:43 pm

A couple things here I’m wondering about. You’re putting add_header_image before your title. With the following tutorial you have to remove the default header and then add your own custom header.

remove_action ( ‘thesis_hook_header’,’thesis_default_header’);
add_action (’thesis_hook_header’, ‘add_header_image’);

Then to put your nav bar below that try this…

remove_action (’thesis_hook_before_header’, ‘thesis_nav_menu’);
add_action (’thesis_hook_after_header’, ‘thesis_nav_menu’);

Reply

Anthony March 4, 2009 at 8:46 pm

This is the tutorial I used to add the custom header : http://www.sugarrae.com/thesis-hooks-dummies-tutorial/#change-header

Its different than yours. Should I just switch to yours? Can I copy and paste?

Reply

Nasty March 5, 2009 at 2:19 pm

They both work well. It’s all about what you like and what gives you the desired effect you’re looking for. Remember the tutorials on this site are just one way of achieving an effect. You’ll start to notice that there are a number of ways to get what you’re looking for.

Absolutely you can copy and past! Keep in mind though that you might have to change the name of functions or selectors because what I use in mine might be different then what you use in yours.

Reply

Anthony March 10, 2009 at 8:18 pm

Still cant get this to work. Using my code for the header, it doesnt pop up. Using your code for a header doesnt show header…. frustrating

Reply

Nasty March 12, 2009 at 12:35 pm

Do you have a link to your site. I’ll see if I can find out what’s wrong.

Reply

Elle April 28, 2009 at 2:24 pm

I’m not sure what I am doing or not doing. Can you please help? I am trying to get my header to display. My URL is http://www.mamaloves.ca.

Thanks.

Reply

Leave a Comment

Previous post: Change the size of widget headline

Next post: How to change the footer