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.

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!

Get Free Updates From Art Of Blog

Insider Updates

Sign up to receive insider tips only available to our email subscribers.

Written by Adam Baird

Adam is a Wordpress designer, Thesis specialist, and blogger from Indianapolis, Indiana. Check out his personal blog or follow him on Twitter for more Thesis tips.

Adam has written 13 posts for Art of Blog!

{ 6 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

Leave a Comment

{ 4 trackbacks }