Thursday, July 19, 2012

Header Changing (Hook)


Thesis Hook Example 1: Changing your Header

Let’s say you want to change your header to include a graphic or logo like my site does above.
Step 1: Upload the graphic you want to add to your header (if applicable) to the custom images folder (thesis > custom > images > put your image here)
Step 2: Open your custom_functions.php file (thesis > custom > custom_functions.php) in your favorite editor
Step 3: Underneath the example code already in the file, place the following code (this code assumes your blog is in the root):
/* Custom Header Image */
function add_header_image () {
echo "<a href=\"http://www.yourblogurl.com/\" title=\"Your Blog Title\">
<img src=\"THE-URL-OF-YOUR-LOGO-GOES-HERE\" alt=\"Your Blog Title\" height=\"170\" width=\"528\" style=\"border:0px\" />
</a>";
}
add_action('thesis_hook_after_title', 'add_header_image');
The /* Stuff Inside Here */ is a label for the code below so you know what it is at a single glance. This is not part of the actual “code”. The word “function” tells Thesis you want it to do something. The add_header_image is what I decided to name that function.
The http://www.yourblogurl.com tells Thesis where to link the blog header image to (usually the homepage) and the “Your Blog Title” tells it what the name of that link (hidden in code) should be. The link after img src is the address of where your logo is located, the alt is “Your Blog Title” (which will show in case the image doesn’t for some reason), the height and width of the image as well as whether or not to give the image a border are all defined next.
The add_action(‘thesis_hook_after_title’, ‘add_header_image’); line tells Thesis that you want it to add a function after the Title and the function you want to add is the one we just created – the add_header_image function. This function utilizes PHP within it, which I don’t fully understand, so that’s about all I can explain folks.
The good news is, this is the most common hook people need to add and to me, is also the most complicated hook. If you can fake make your way through this, you’ll be fine.

No comments:

Post a Comment