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.

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!

Sign Up Now for Free Updates and Exclusive Content:

Learn how to write killer content, get more traffic, make money, and more by entering your email below:

Written by Adam Baird

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.

Comments

  • 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!

  • Tom says:

    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

  • Travis says:

    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

  • [...] easy to make. This is absolutely ideal for bloggers that cannot be bothered with learning all the nuts and bolts of a WordPress theme, but simply want to start blogging. With no tech degree needed to make a site [...]

  • [...] Thesis Hooks 101: An Introduction to Thesis Hooks – This is the Art of Blog guide to Thesis Hooks. If you’re a complete beginner with hooks, this is the place to start. [...]

  • [...] your blog with the custom.css and custom_functions.php files. After learning about how to use Thesis hooks, you will be able to start customizing your theme is no time [...]

  • [...] Thesis Hooks 101: An Introduction to Thesis Hooks [...]

  • alwin says:

    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

  • [...] you’d like, you can find out more about the way that Thesis handles hooks and custom [...]

  • vitamin says:

    “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?

  • Aliza Shehpatii says:

    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!

  • Steve @ Games Tables for Kids says:

    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

    • Adam Baird says:

      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.

  • Michael says:

    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.

  • Charles says:

    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

  • Cat Alexandra says:

    FANTASTIC!! Thank you! Worked beautifully! :D

  • Jake says:

    Great article… but, what’s up with your opt-in box popping up every 3 minutes or so? I’m using chrome. Not sure if thats intentional or a programming glitch from the browser.

  • Jim says:

    I can add a function to a hook (some of them) but when I try to remove the function from a hook, it won’t work. There are about 25 different names of hooks in the ‘content’ or ‘post’ area. Not really any way to tell which is which.

    I tried removing the same function from EVERY hook on the list. Amazingly it still runs the function. Also, if you end up with two duplicated functions, since can’t remove the function, only add, everything you do to one happens to the other. Can’t even make the duplicate invisible! Nightmare!

  • Linda says:

    As a real beginner. What, pray tell, is a “hook”? Thesis is generous in it’s praise of hooks and how great they are, but I have yet to find a definition of a hook and how to use it to improve a website in non-technical language.

    • Eric Binnion says:

      Hey Linda,

      Hooks are a way to add code to a particular part of a theme without hacking away at theme files. They do take a bit to learn, but they are powerful once you learn them :)

  • Hi Adam,

    I’m super close to being persuaded to switch from my 2012 WordPress theme to Thesis. The overwhelming attraction to Thesis was the fact (or so I thought) that I wouldn’t have to deal with any code. Now after reading some tutorials here at artofblog.com …..it seems you do have to know code. What gives?? Is this just in the event that you want to customize further beyond the “built in” stuff?? I want more freedom than I have with 2012, but I don’t want to stress out over code with all its: ?{ , and all the rest…..

    Please enlighten me.

    Thanks,
    Cathy

  • Kim says:

    Hi Adam,

    Thank you for this great post. Any idea what the exact code would be to remove the “Get smart with the Thesis WordPress Theme from DIYthemes” footer without altering the php file? Can it be done in Openhook? I’m also trying to add menus in my footer..but since I’m not a coder….YIKES! lol

  • Ethan Talley says:

    I’m trying to add several tabs onto my thesis blog but my content only shows in one area instead of the areas it’s suppose to be in but I also want it featured in the news section.how would I label my articles in the tab it’s in while also showing up in my news tab?my blog is under construction so it may look empty.thank you for your time