Aweber - Email Marketing Made Easy
Thesis Hooks – A Simple Explanation Photo by: bagaball

Thesis Hooks – A Simple Explanation

August 1, 2010 · 3 comments

in Thesis

Thesis 1.x Notice: Thanks for reading this post! So, here's the deal. I wanted you to be aware that this post was written prior to the release of Thesis 2. So that means the instructions or other information provided applies specifically to Thesis 1.x and not the latest 2.x version. Thanks!

Much has been written about Thesis hooks and why they’re so powerful when it comes to customizing your Thesis theme. Before I sat down to write this post, I questioned whether it’s really necessary to write a post about something that has already been explained on numerous other blog posts about Thesis hooks. Then I considered the learning curve I had to go through in order to really grasp the concept, and I decided to explain it in my own way. Hopefully this will offer up a different perspective on Thesis hooks, and will make the concept easier to grasp for those of you who still don’t fully understand how it all works.

I also want to mention that the goal of this tutorial is not to dive too deeply into the details of Thesis hooks or functions, but rather to offer an explanation of the overall concept of hooks. I feel that once you have an understanding of a concept, then the details make more sense, and almost fall into place for themselves. Also, there’s a bunch of other great blog posts out there that do get into the details, and I’ll include some of them in my Thesis hooks reference list at the end of this post.

Thesis Hooks

So let’s get into it. Thesis hooks are really just placeholders, or anchors located at numerous strategic locations throughout the Thesis theme. They provide us with the ability to attach additional code to any of these hooks, and we’re also able to remove hooks if needed.

To help you visualize this, I created this rough diagram. This represents visually how the hook system works. Click the image to enlarge it.

Thesis Hooks

The location of the hooks in my diagram are not intended to be 100% accurate. I just want you to get the concept. You basically have the strategically placed hooks in the Theme, and then your code is either written in your custom-functins.php file or pasted into the applicable field in your Thesis openhook plugin. And the code is then attached to the specific hook location. Got it?

Hooks are not unique to Thesis. WordPress has it’s own default hooks, and so do certain other theme frameworks. Thesis has an extensive list of available hooks to which you can attach code. Hooks are just as easy to understand as adding code the “non-hook” way. That involves opening up an index.php file for example, finding the spot where we want to add some code, and then pasting the code in that location. When it comes to hooks, the major difference of course is that instead of inserting the code directly into a core theme file, we’re inserting it into the custom-functions.php file, or a field in the openhook plugin. At the very location where we’d have pasted in our code, Thesis has intelligently placed a “hook” in that location, so we can access it, or “hook” some code to it. It’s the smarter way to go.

Thesis Functions

I think the part that most people struggle with may have more to do with creating the functions inside of the custom-functions.php file. The Thesis openhook plugin makes this part really easy. You just paste the code in the applicable hook field of the plugin. If you’re just starting out learning Thesis, this may be the way to go. You don’t have to mess with custom functions, however I’m of the opinion that all your code should reside in the custom-functions.php file. So if you really want to move to the next step with Thesis hooks, it would be best if you could get a handle on how to write these functions.

Here’s the basic structure of a custom function you can include in the custom-functions.php file, along with the action to attach it to a hook. In this example, the thesis_hook_after_post part is simply the name of the hook so the theme knows where to attach your code:

function my_function() {
?>
	<p>Insert your HTML code here...</p>
<?php
}

add_action('thesis_hook_after_post','my_function');

I’d recommend you read the Thesis Hooks. A Complete Newbies Guide post over at thinkdave.com. It gets into more detail on how easy it is to create these functions, and explains each line so you can really get an understanding of the syntax. When I finally got it, I wondered why I didn’t get it before. It’s not that difficult a concept to grasp.

HTML, CSS, PHP & WordPress

The reality is that to really know how to customize Thesis, you need an understanding of HTML, CSS, PHP and WordPress. Once you get how Thesis hooks work, you still have to write the necessary code, style it and make it function how you want, so it’s important to also learn about these other parts of the formula.

Of course, there’s nothing wrong with finding some code that has already been written and made freely available for you to paste into your files. That can also be one of the best ways to learn. Look at what someone else has created; who may be further along in the process, and learn from it.

Thesis Hooks Reference List:

Was this post helpful? Consider subscribing to my blog via RSS or

This Site Runs on the Thesis WordPress Theme

Thesis Theme thumbnail

If you're someone who doesn't understand a lot of PHP, HTML, or CSS, Thesis will give you a ton of functionality without having to alter any code. For the advanced user, Thesis has incredible customization possibilities via extensive hooks and filters. And with so many design options, you can use the template over and over and never have it look like the same site.

If you're more familiar with how websites work, you can use the fantastic Thesis User's Guide and world-class support forums to make more professional customizations than you ever thought possible. The theme is not only highly customizable, but it allows me to build sites with a much more targeted focus on monetization than ever before. You can find out more about Thesis below:

{ 3 comments… read them below or add one }

Dr. Lawrence Kindo August 11, 2010 at 11:47 am

I am a Thesis user with the least knowledge of html, CSS, or worse still PHP. I can barely understand the ins and outs of the wordpress dashboard. Thanks to the many people who have made tutorials available with some awesome code snippets that makes work easier for folks like me.

I am beginning to see some really good posts out here. The customization on this site is great – I am mighty tempted to flick some ideas from here.
Dr. Lawrence Kindo recently posted..Why I Decided to Enter a Blogging Contest

Reply

Aliza Shehpatii April 15, 2011 at 11:34 pm

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. A simple yet meaningful guidance for me to start loving my thesis and make it worth every penny I’ve spent!
Aliza Shehpatii recently posted..Amir Khan vs Paul McCloskey Live stream Highlights 16 April 2011

Reply

Charles December 14, 2011 at 7:03 am

“…I questioned whether it’s really necessary to write a post about something that has already been explained… Then I considered the learning curve I had to go through…”

Wow, thank you. I’m very appreciative that you thought of it like this and explained it in your own way – a great boost to my understanding! Cheers, and happy holidays.

Reply

Leave a Comment

When commenting, you can use basic HTML tags. If you are pasting in any code, please escape it here and then include that code within <pre></pre> tags. Thanks!

CommentLuv badge

Previous post:

Next post: