Thesis Hooks 101: An Introduction to Thesis Hooks

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.

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!

Adam has a decade of experience as a WordPress designer and developer. Learn more about him here.

Written by

Adam has a decade of experience as a WordPress designer and developer. Learn more about him here.

«
»

Comments are closed.