Thesis Hooks 101: An Introduction to Thesis Hooks

Summary

So, you’ve got the installation done, and you’re ready to start with the customization process. The first thing you need to do is familiarize yourself with Thesis hooks. Thesis uses a vast array of hooks to allow you to place content just about anywhere you want on your blog. You can also remove a lot of the default thesis elements if you want to.

thesis-hooks-101

Adding an element to your Thesis design is very simple. It is basically a two step process:

  1. Write a WordPress function in custom_functions.php
  2. Attach that function to a hook

Before, you scream and run for the hills, let me take you through this. Its actually very simple. There is a bit of a learning curve, but once you figure it out, you’ll never want to do things any other way.

YouTube Preview Image

Creating a Simple WordPress Function

WordPress functions are extraordinarily simple to write. Here is what an empty one looks like:

function NAME() {
 ?> <?
 }

The word “function” allows wordpress to identify this as a function. “NAME” is just the name of this particular function. We can name it whatever we want. Finally, “{ ?>

Now, let’s go ahead and add a bit of code to the function we just created and we’ll actually give the function a name other than “NAME”:

function affiliate_link() {
?>  <p>Get Smart with the <a href="http://www.diythemes.com/your-affiliate-link">Thesis Theme</a> from DIY Themes!</p>
<? }

And that’s it! You’re done creating the function. That wasn’t too painful was it? We named the function and added the content we wanted (in this case, an affiliate link). Obviously, you can get quite a bit more creative, but for the purposes of this guide, we’ll keep it simple.

Hooking Our Function

This is where you need to learn a bit about hooks. Its not that complicated, but it can be confusing. Basically, if you add a function to a hook, the content contained in that function will appear at the location of that hook. If you add more than one function to a given hook, the content from the function added first will appear first. Make sense? Here is a list of hooks that are available to you. If you are more of a visual person, you can see the hooks mapped out here.

In order to remove a function from a hook you use this:

remove_action('thesis_hook_we_are_using', 'name_of_function_we_are_removing');

In order to add a function to a hook you use this:

add_action('thesis_hook_we_are_using', 'name_of_function_we_are_adding');

So, let’s add our affiliate link in place of the standard thesis footer attribution link. The text is virtually the same, but we want to make some $ for all of customers we are sending Mr. Pearson’s way! Our function we just wrote includes our affiliate link. The standard Thesis attribution does not. Let’s replace it.
In order to replace it, we first need to remove the default attribution. That looks like this:

remove_action('thesis_hook_footer', 'thesis_attribution');

Thesis_hook_footer is the name of the hook we are using, and thesis_attribution is the function we are removing. Now, let’s replace it with our affiliate link!

add_action('thesis_hook_footer', 'affiliate_link');

Any of this code we use is placed in custom_functions.php in our Thesis custom folder. In the end this is what we’ve accomplished:
hookexample
You can apply this concept to virtually any idea you have. You can add anything almost anywhere to your blog design. That really is the freedom that Thesis grants you.
Also, keep in mind, you can add your own functions without removing the default Thesis functions. Rather than removing the default Thesis attribution, we could have just added another paragraph below it. All we would have done differently is leave out the remove_action code.
On the same token, you can remove anything you like, and you don’t have to replace it. The choice is yours. For a list of removable Thesis objects, click here. That is by no means an exhaustive list, but it should get you started nicely.
I understand this is somewhat complicated stuff, and I’m more than willing to answer questions and/or clarify in the comments!

Make More Money From Your Blog

Insider Updates

Learn how to make more money with actionable no-nonsense marketing tips. Sign-up below and immediately receive our 5 part blog marketing crash course.

Written by

Adam is a Wordpress designer, Thesis specialist, and blogger from Indianapolis, Indiana. He writes web design tutorials and resources on Theme Big. Check out his custom work here.

Adam has written 16 posts for Art of Blog!

{ 16 comments… read them below or add one }

Michelle Salater February 11, 2010

I’m not a programmer, and I’m unfamiliar with coding thesis hooks, but you broke down creating Wordpress functions in a way that I can easily understand! Thank you!

Reply

Adam Baird February 12, 2010

Glad I could help!

Reply

Tom February 17, 2010

Is there supposed to be a video in addition to your article…seems like there is a space for one..
Adam, I like your teaching style..

Thanks,

Tom

Reply

Adam Baird February 17, 2010

Tom,

Appreciate the kind words. There is a youtube video in that space. It shows up just fine for me. Reload the page, clear your cache and make sure you flash is up to date.

Hope that helps!

Reply

Tom February 17, 2010

Voila….it is there now..
Thank you very much..

Reply

Travis March 15, 2010

Adam,

Thanks for this easy-to-follow intro to hooks. I literally just purchased Thesis and I’m a bit overwhelmed with all the customization options available (which is a good thing).

One question I had with this is that I purchased the personal version of thesis which doesn’t allow us to change the attribution at the bottom. Does this include the changes you’ve made in your example? Basically, can we implement your example with the personal license of Thesis? Just curious.

If you have any other tips or places I might want to head for guides/tutorials etc, please please share! I’m all over the place right now and could use some focus :)

-Travis

Reply

alwin August 30, 2010

I already got the HOOKS my problem is, where can i get the list of default FUNCTION of thesis, so i can add remove them

Reply

vitamin September 21, 2010

“I already got the HOOKS my problem is, where can i get the list of default FUNCTION of thesis, so i can add remove them”

@ alwin,

I was wondering the same thing?

Reply

Nick Reese September 21, 2010

http://diythemes.com/thesis/rtfm/hooks/
Contains all the hooks.

To remove an action use the following format:
remove_action(‘thesis_hook_header’,'thesis_default_header’);

Reply

jerry lee April 19, 2011

I know this is a silly question but why not just delete the existing action? OH, I think I just figured it out, when I upgrade, it would put it back… Right? Kind of like child themes?

Reply

Aliza Shehpatii April 16, 2011

Just bought Thesis for a few days and still looking around for a useful hints on hooks and functions for a newbie cum non-technical guy like me.

Thankfully I’ve managed to discover your site, Adam Baird. A simple yet meaningful guidance for me to start loving my thesis and make it worth every penny I’ve spent!

Reply

Steve @ Games Tables for Kids May 27, 2011

Hi Adam
Thanks for your video and explaining about hooks.
Just one question;-
You explain about ‘removing’ the existing attribution andadding our own, but could we not simply replace it? By changing the text from ‘thesis_attribution’ within the line of code and then replacing it with ‘affiliate_link’ in the same place.

This then would save the extra line ‘remove_action’

Just thinking logically and how I would normally replace links etc in html generally

Regards
Steve

Reply

Adam Baird May 30, 2011

Steve,

PHP is a bit different than HTML. If you don’t remove the “thesis_attribution”, “affiliate link” will simply appear below it.

Hooks are not limited to one function. If you add multiple functions, they will just show up in the order you add them.

Reply

Michael June 20, 2011

Hey Adam, those magic tricks look easy when you do them. But for me, I wouldn’t even attempt to do those hooks. I bought thesis 1.8 and must say its a great theme but I dont use it coz I am technophobe and cant even make menu tabs :(. I created a page and though it will auto create the tab but no way. Its to difficult for me.

Reply

Charles August 25, 2011

Great help, Adam.

I’m new and still getting used to the Thesis structure. In this tutorial, you removed and added the footer hook, but you didn’t explain how you knew which function (the actual name) to specify to remove it. How can one figure out which functions are actually being used in the hooks?

Thanks,

Charlie

Reply

Cat Alexandra October 7, 2011

FANTASTIC!! Thank you! Worked beautifully! :D

Reply

Leave a Comment

{ 5 trackbacks }