If you're new here, you may want to subscribe to my feed or subscribe to me on Twitter, which is updated on a more frequent - and more meaningless - basis.
By now, most people know that I am an evangelist for the Thesis theme and that the Sugarrae site actually runs on the theme.
When Chris Pearson announced the newest release of Thesis, it touted a bunch of great new features and fixed most of my previous gripes. Users who don’t know CSS or PHP have more control with the new thesis them than with any other theme I’ve ever seen.
It looked completely awesome until I downloaded it and saw that Thesis was now run completely on “hooks”. Not only did I not know what a hook was, the tutorials and discussions I saw about it scared the hell out of me.
My level of PHP knowledge (the code language WordPress is run on) is slight at best, thus why I was so thrilled in my earlier review:
You can do everything Thesis does without putting down any money buying the theme. Hell, you could also do this with wordpress if you knew how to (yes, no shit).
Now, you might be someone who can do all this without buying Thesis.
However, I am not. So I bought Thesis.
Now I suddenly was in need of “hooks” to do any “out of the ordinary” customizations (such as adding social bookmarking plugins). I opened up my index template and saw this (and ONLY this):
<?php thesis_html_framework(); ?>
The single post template was missing. The tutorials were in Japanese as far as I was concerned. Thesis was now either for the very basic or the very advanced… those of us hacking plugins into core files were out of luck. What the hell was I supposed to do now?
So I whined to told Pearson that I didn’t understand this or like this one bit. He assured me hooks were easy. He assured me once I learned them, I’d love them. He sent me a link to one of the tutorials. I suddenly realized how people who don’t know SEO must feel reading a document about latent semantic indexing. I also decided I was going to force Pearson to teach me how to do it so I could help non-programmers understand hooks the way Aaron helped the non technical understand LSI. Luckily for me (and hopefully you), he obliged.
The below is the completely “not technical” explanation of hooks, why you need them and how to make them (with examples you can then hack away with). It is chock full of incorrect terminology (I’m pretty sure “put this stuff here” is not part of any PHP instruction manual) and if you’re a programmer, you can go read the properly written tutorial here and spare me on showing me the size of your programming penis by pointing out how small mine is in the comments. ;-)
If you’re scared of that tutorial, confused and can’t follow these instructions:
1. construct a simple function to house your custom HTML
2. tell Thesis where to place your custom code by specifying the appropriate hook
Because you a. don’t know what a function is b. how to write one c. what a hook is or d. how to find “the appropriate” one, then you might want to check out the below.
How to Use Hooks without Learning Japanese
Hooks are basically each section of your theme separated into a single part as well as ways to define areas before and after those parts. Your header is controlled by one hook (thesis_hook_header) while you can use other hooks to put any code you choose before (thesis_hook_before_header) of after (thesis_hook_after_header). Every area has a hook and most areas also have hooks that will allow you to place things before or after them. Instead of the PHP code appearing on the actual page, only the call to the hook that says “put what’s in this hook here” does.
Hooks define where stuff appears and functions define what stuff appears.
A function is essentially code you can assign to a hook that should appear within a hook. For example:
function your_function_name() {
?>
YOUR RAW HTML
<?php
}
Hooks are basically the various parts of your blog, and functions are things that appear within them so to speak.
Now that you know what a hook is and what a function is, we’ll talk about how to add functions to your hooks to do things like add your own graphic into your header or add in social bookmarking buttons.
First things first, never change or edit existing hooks or functions. If you’re looking for the file that contains the core hooks or functions to change them, stop in your tracks. Unless you’re a programmer by trade, you will only risk messing something up by touching them. You never change existing hooks or functions in the core files - you simply add additional functions or replace existing functions with new ones.
Thesis will check your custom_functions.php for instructions and cross reference it so to speak with the core files. If you have removed a core hook or added an additional hook in the custom_functions.php file, then it will override the commands in its core files. (I’m no programmer folks and have already given you my disclaimer on using proper technical terminology to describe this above.)
The way I learned hooks was by example, so I am going to (attempt to) do the same here.
Thesis Hook Example 1: Changing your Header
Thesis Hook Example 2: Adding Social Bookmarking Icons
Thesis Hook Example 3: Changing the Thesis Footer
Thesis Hook Example 4: Adding the Social Profiles Plugin
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.
Thesis Hook Example 2: Adding Social Bookmarking Icons
This hook will show you how to add some social bookmarking or social media buttons to the bottom of only your single post pages (the actual page your full, individual blog post lives on) like my site does.
Step 1: Upload the graphics you want to use to link to the social sites (if applicable) to the custom images folder (thesis > custom > images > put your images 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 and is to place Stumbleupon, Digg, Delicious and a link to your RSS at the bottom of each individual post on your blog):
/* Custom Social Media After Post Hook */
function add_social_media () {
if (is_single()) {
?>
<p><a href="http://www.stumbleupon.com/submit?url=<?php the_permalink() ?>"><img src="THE_URL_OF_YOUR_STUMBLE_GRAPHIC"></a><a href="http://digg.com/submit?phase=2&URL=<?php the_permalink() ?>"><img src="THE_URL_OF_YOUR_DIGG_GRAPHIC"></a><a href="http://del.icio.us/post?url=<?php the_permalink() ?>&title=<?php the_title(); ?>"><img src="THE_URL_OF_YOUR_DELICIOUS_GRAPHIC"></a><a href="http://www.linktoyourfeedhere.com"><img src="THE_URL_OF_YOUR_STUMBLE_GRAPHIC"></a></p>
<?php
}
}
add_action('thesis_hook_after_post', 'add_social_media');
Same as before, 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_social_media is what I decided to name that function.
The if (is_single()) is a conditional tag that basically tells Thesis to only use that function if the page is the single post page. If I changed it to be is_category() it would only run this function on category pages. You can find a full list of conditional tags here. If you wanted to change this to show the social bookmarking buttons on every page of the site, you’d remove the (is_single()) and the following { and later } like so:
/* Custom Social Media After Post Hook */
function add_social_media () {
?>
<p><a href="http://www.stumbleupon.com/submit?url=<?php the_permalink() ?>"><img src="THE_URL_OF_YOUR_STUMBLE_GRAPHIC"></a><a href="http://digg.com/submit?phase=2&URL=<?php the_permalink() ?>"><img src="THE_URL_OF_YOUR_DIGG_GRAPHIC"></a><a href="http://del.icio.us/post?url=<?php the_permalink() ?>&title=<?php the_title(); ?>"><img src="THE_URL_OF_YOUR_DELICIOUS_GRAPHIC"></a><a href="http://www.linktoyourfeedhere.com"><img src="THE_URL_OF_YOUR_STUMBLE_GRAPHIC"></a></p>
<?php
}
add_action('thesis_hook_after_post', 'add_social_media');
The rest of the code is the traditional HTML code you’d use to add those bookmarking buttons to your theme normally.
The add_action(’thesis_hook_after_post’, ‘add_social_media’); line tells Thesis that you want it to add a function after the post content and the function you want to add is the one we created - the add_social_media function.
Thesis Hook Example 3: Changing the Thesis Footer
A lot of times people want to customize their footer to add copyright notices or other information. The example below will show you how to change your Thesis footer link.
Step 1: Open your custom_functions.php file (thesis > custom > custom_functions.php) in your favorite editor
Step 2: Underneath the example code already in the file, place the following code:
/* Custom Footer Hook */
remove_action('thesis_hook_footer', 'thesis_attribution');
function add_custom_footer () {
?>
<p>© 2008 Ourblog.com - All rights reserved. - <a href="http://www.ourblog.com/privacy-policy/">Privacy Policy</a></p>
<p>No content on this site may be reused in any fashion without written permission from Ourblog.com or whatever you want your footer to include</p>
<?php
}
add_action('thesis_hook_footer', 'add_custom_footer');
Again, 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 remove_action(’thesis_hook_footer’, ‘thesis_attribution’); tell Thesis that you wish to remove the regular Thesis footer function (thesis_attribution which we know is the default function the hook uses) from the thesis_hook_footer (the hook we know generates the footer). The word “function” tells Thesis you want it to do something. The add_custom_footer is what I decided to name that function.
The HTML for what I want to appear in the footer is added and then the add_action(’thesis_hook_footer’, ‘add_custom_footer’); line tells Thesis you want to add a function to the thesis_hook_footer (the hook that creates the footer) and the function you want to add is the one we created - add_custom_footer.
So, the code above essentially says “Hey Thesis, please remove the code (thesis_attribution) you put into the footer (thesis_hook_footer) by default and replace it with our code (add_custom_footer). You can do that with any hook function you’d like.
Thesis Hook Example 4: Adding the Social Profiles Plugin
If you’re using the Social Profiles plugin we created here at Sugarrae, the following code will show you how to get the plugin output to appear in your comments area in the same way they appear in mine (after the author’s name, the date, etc but before the comment).
Step 1: upload and activate the Social Profiles plugin
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:
/* Custom Social Profiles for Comments Addition */
function add_social_profiles () {
global $comment;
?>
<?php cyc2_show_profiles($comment->user_id); ?>
<?php
}
add_action('thesis_hook_after_comment_meta', 'add_social_profiles');
Per usual, 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_social_profiles is what I decided to name that function.
The PHP code for the plugin is added and then the add_action(’thesis_hook_after_comment_meta’, ‘add_social_profiles’); line tells Thesis you want to add a function to the thesis_hook_after_comment_meta (the hook that creates the name, date, number, etc of commenters) and the function you want to add is the one we created - add_social_profiles.
Thesis Hooks are Easy
Above, I’ve shown you an example for changing the header (the most common customization you’d need to understand the hooks to do), how to add something to only one specific template (to a single page, to a category page, etc), how to add something to every page, how to remove a function from a hook and add a new one (the footer example) and how to add plugin code (in this case, by adding Social Profiles to the comments area as an example).
You’ll also find the following documentation (linked above in the examples) to be of use to you when using functions and hooks as well:
- The official hooks tutorial
- Thesis hook reference list
- Default hook usage in Thesis
- Listing of the conditional tags you can use with WordPress
If you’re using the Thesis Theme already, I hope you find this tutorial to be a help in customizing the new version. If you’ve been on the fence about Thesis, I hope this has shown you hooks aren’t anything to be afraid of and that you can still customize Thesis without being a PHP guru. If you’re ready to make the leap to Thesis, you can get your copy of Thesis here.
Subscribe to the Sugarrae feed | Follow Sugarrae on Twitter
Related Posts
Sugarrae runs on the Thesis WordPress Theme
If you’re a blogger looking for a professional prescence but don’t understand a lot of PHP, Thesis will give a ton of functionality that you wouldn’t be able to obtain otherwise with a simple control panel. With the incredible customization possibilities via Thesis hooks, you can easily make your blog stand out from the crowd.
Thesis allows bloggers to make more professional customizations than they may have ever deemed possible due to lack of coding knowledge. The theme allows me to run Sugarrae more professionally, with a focus on monetization that is more targeted than I’ve ever been able to achieve with a theme before. You can find out more about Thesis below:







{ 5 trackbacks }
{ 38 comments… read them below or add one }
Find me at Sphinn | Twitter | WebmasterWorld
Very informative and timely post Rae. I haven’t upgraded to 1.3 yet because I’m a bit rusty with hooks. Thanks a million, between this and the official hooks tutorial I’m straight!
Dear Sugarrae,
Please keep blog posts to no longer than three paragraazzzzzzzzz
zzzzzzzzzzzzzzzzzzzsnore…………
:)
Find me at Sphinn | Twitter | WebmasterWorld
@wheel
LMAO… hey, if you were impaired with this stuff like I am, you’d be ever so thankful for this ;-)
Find me at Twitter
I was looking for this kind of explanation and found it on ThanksGiving Day here in the US. Thanks Rae!
Find me at Sphinn | Twitter | WebmasterWorld
The long break down was definitely appropriate. This was one hell of a helpful post, especially as I delve more into thesis. Thanks Rae!
Find me at Sphinn | Twitter
I’ve been learning as much as I can about hooks over the past couple months and this is by far the best straightforward tutorial that I’ve seen. Thanks!
Find me at Sphinn | Twitter
Great tutorial - thank you! Much more straightforward than the explanation in the Thesis manual.
One tweak I had to make when using the custom header hook - the first time I tried it, I ended up with a space between my header image and the double horizontal lines below it. Adding this to my custom.css fixed it:
.custom #header { padding-bottom: 0; }
thank you for your in-depth reviews. Your thesis review that you did a few weeks ago, or that I found last week, was awesome.
Because of that review, and the step-by-step detail that you took, I proudly purchased through your affiliate link. Hopefully the little change you received will help out with some gas money.
Find me at Sphinn | Twitter
thanks so much! I just grabbed thesis yesterday and I’d come across add_action but I hadn’t yet seen remove_action. I was struggling with how to override built-in functions.
With CSS, you have the cascading properties, so putting things in the custom.css file won out over defaults. Function calls don’t behave the same way, so I was really struggling until I read your post.
Thanks again - off to go code!
Rae,
I’m pretty shocked to learn that you don’t know much about programming. Looking at your site (which is probably one of the best Thesis Mods I’ve seen), It appears you don’t need to be one.
Did you ever teach? As a former one myself, I can say you’ve got the skill!
A long time back (when I first started screencasting) I put together some tutorials for Tubetorial on HTML, and later did some TeachingSells Vids. I can’t wait to jump into Thesis and create some Thesis Mod vids. I look at sites like yours and it gives me the motivation I need to kick myself in the ass and get R done.
Regards
Shane
Find me at Sphinn | Twitter
Super cool Rae - this is *way* easier to understand than what I had to learn from in the forums. Your footer example is perfect - I modified my site’s footer directly and had to change it back every time upgraded to a new version of Thesis. Not any more!
Also - I just ran across this great plug-in for Thesis: OpenHook. It adds and admin panel to WordPress Design panel and allows you to add code for the various hooks right from there. Great tool for those who don’t want to modify their custom_functions.php file.
Anyway, thanks for this great post!
Find me at Twitter
Very awesome post, thanks! I’ve been hearing more and more about Thesis and while I can get in and destroy the back end of WordPress, it takes me to long and… the whole putting it back together after I destroy it part. That part sucks. Sounds like Thesis is what I need.
I have used WordPress for almost a year now. I was afraid to switch themes because of the heavy customization I’ve done to mine. But I bit the bullet and bought Thesis at their sale last week. Whoa!
This whole bit with hooks is pretty slick. And now I earn that I’ve been doing it wrong all this time.
Find me at Twitter
Thanks for this. I DO speak Japanese and I was still lost!
I love your sense of humor, I won’t be messing with you anytime soon. Great post!! I speak limited ‘japanese’ but you dumbed it down enough for me.
RAE!!!!!!!!!!!!!!!!!!!
Thank you so much for this! I’m still using 1.1 and a bunch of custom stuff I’m used to doing. But this explanation of hooks is definitely something I’ve been needing for new projects.
Thanks for the post. Very straight-forward. Quick question: how would I go about customizing my sidebars? The forum posts and thesis guide are over my head, lol.
Thanks.
Find me at Sphinn | Twitter | WebmasterWorld
@ceasor almost anything can be added via the widgets on the sidebar, even PHP based functions provided you use the Samsaran PHP widget plugin. Let me know what it is you’re trying to do specifically and I’ll see if I can help.
Thanks. I’ll dive into the widgets. I pretty much want you have on this blog: Newsletter subscription, Categories, Top Posts, Recent Posts, embed youtube clips, etc.
Thanks.
I don’t get it. I add it like this:
/* YOAST BreadCrumb */
function yoast_breadcrumb () {
<?php if ( function_exists(’yoast_breadcrumb’) ) {
yoast_breadcrumb(”,”);
} ?>
}
add_action(’thesis_hook_before_title, ‘yoast_breadcrumb’);
and nothing … when I try to access the site I get
Parse error: syntax error, unexpected ‘<’ in wp-content/themes/thesis/custom/custom_functions.php on line 37
Rae can you point me what I’m doing wrong. I don’t like these hooks, he’s over complicating simple things.
Find me at Sphinn | Twitter | WebmasterWorld
@ceasor I just use text widgets to embed the youtube videos etc in the sidebars. :)
@matej try this:
/* YOAST BreadCrumb */
function yoast_breadcrumb () {
global $comment;
<?php if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} ?>
}
add_action('thesis_hook_before_title', 'yoast_breadcrumb');
and let me know if it works.
Rae, new code is not showing me error message anymore but breadcrumbs are not showing. I asked Kristarella about it on forums, hopefully she will help me.
Thank you, I really appreciate it!
Thanks Rae. It worked great.
I have been searching the web for hours for instructions that make sense. I knew that once I understood this it’d be extremely convenient, but I didn’t think I could get there. You have just saved me so much time. You kick ass. Thank you, thank you, thank you.
Yesterday I came across the Thesis theme by accident, and got intrigued. I looked at a lot of samples that I found from a thread in their forum. Liked some a lot. Googled thesis theme review and found your site.
This page finally convinced me to go for it, so I bought through your link, and signed up for your RSS feed.
It’s Christmas Eve… I may be up late enough to see Santa, playing with the theme!
Thanks Rae, just like everyone else your tutorial is so much easier to understand.
I do have a question in regards to the custom header, where do I find THE-URL-OF-YOUR-LOGO-GOES-HERE? I’ve only just bought thesis and paid for a web host for the first time four days ago so I’m pretty new at this game.
Your help with this matter would be appreciated, thank you.
Kindest regards,
Lia Halsall
Okay Rae, after much trial and error I finally got my header image up on my blog. Only two challenges now:
1. How do I remove the blog title ONLY from the blog and not the dashboard?
2. How do I centre the image instead of it being left aligned?
Sorry to bother you once again.
Kindest regards,
Lia Halsall
Find me at Twitter
Very useful post.
Question on your style. Did you create the “Sugarrae runs on the Thesis WordPress Theme” box in your style.css, then add a thesis_hook_after_post to show it (after every post, like the name says)?
Hi Rae
I downloaded the Thesis theme a couple of weeks ago now and I’ve been trying to change a couple of things which is very difficult when you’re not a techie. I want to change the footer information on my blog and I’ve asked this question on the Thesis forum but I haven’t received a reply yet. This might have something to do with the fact that it’s New Year’s Eve and everyone will be wanting to party! - Anyway, I’ve read your explanation above about ‘hooks’ and I’m just about to implement what you’ve said about changing the footer. You’ve laid it out in a simple manner so I should be able to follow it. I think the people at Thesis should create video tutorials for every question that they get asked in the forum and post them on YouTube so that we can watch them over and over again. I think they’re assuming that everyone using the theme has a bit of programming knowledge which is definitely not right in my case.
Thanks for sharing this clear cut guide.
John O’Hara
United Kingdom
P.S. I also want people to have the option of subscribing to my blog via email and I like how you’ve done this and the location at the top of your blog is perfect. If you don’t mind, I will copy this when I get my head around these ‘hook’ things!
Find me at Sphinn | Twitter | WebmasterWorld
@Lia
@John subscribe to the feed - I’m doing a ton of these tutorials in the coming months to show non programmers how to customize their theme :)
@Richard subscribe to the feed… there’s a little more to my blue boxes than that and I’ll be showing folks how to do it with my next tutorial. It’s similar to the ad targeting tutorial but a little different.
Hiya Rae
Thank you for replying to my comment.
Great News…I’ve been able to change the footer on my blog thanks to your simple explanation above. I’m really pleased with myself, it’s a small victory!
I will subscribe to your feed via email as soon as I finish writing this comment.
I’d like to also ask you something else?
Can you tell me how to add the ’subscribe via email’ text and functionality to my blog exactly as you’ve done it? I want people to be able to receive email updates to my blog via feedburner.
Find me at Sphinn | Twitter | WebmasterWorld
John, I can put together a tutorial for that, but it won’t be til the next week or two.
Hi Rae-
I successfully executed a basic hook to put some content before the content, and I styled the text inside this box in the custom.css file, but how do I style the box itself? You can see it at the link below:
supportvilsack.com/test
I’d like to add some padding on both sides, how do I do that? Help, thank you!
Oh my god, it worked. I am a grade above retarded when it comes to PHP or CSS or HT-whatever so I can’t believe that this tutorial worked.
Thank YOU so much. I’m launching the new Thesis theme on my blog on Monday and I can’t thank you enough for helping me understand this.
Thanks for the tutorial Rae! I’ve tried to wrap my mind around hooks before and your explanation was just what I needed! Between you and kristarella, I’ve got this thing down.
I should be redesigning in the next couple of days :)
Fantastic,
I’ve been banging my head against the wall trying to learn customizations. This was such an easy to read tutorial, I really appreciate the time you took to share.
I recently started using ‘Prestashop’ as a ecommerce platform and that is based around hooks, I didn’t know where to start so I read a few articles on the web and they all went over my head. Thanks so much for breaking it down to a simpler level, much appreciated!
This article has helped me soooo much Thank You Rae
Ohhh How I so much want to use my new design with Thesis….
But I can’t figure out how to get a full variable width header and footer!!
Any help is absolutely appreciated!!