Thesis Banner

Thesis Hooks Explained

by Chris on February 19, 2010

To really customize Thesis the way you want to, you need to understand Thesis hooks. At first glance, hooks seem like a daunting concept to learn, but they really are quite simple. In this article, let me explain to you what Thesis hooks are, and how to take advantage of them on your site.

Hooks themselves are a WordPress concept. They were added into WP to provide plugin developers a way to call their own custom functions at specific times. There are actually two different types of hooks, Actions and Filters. Actions occur are hooks that are called at specific points in time or when a specific event happens. So there’s a WordPress hook called publish_post, and if you add your action to that hook, it will be called whenever someone publishes a post on the site. Filters are slightly different. They are called when WordPress is doing something with data (ie. text) like displaying it on the screen or saving it to the database. This allows you to add your own filters to modify the data in your own specific way. For example, you could add your own filter which would link to the Thesis homepage whenever it sees the word “Thesis” in a post.

There are hundreds of built in WordPress hooks, but they’re not particularly helpful for customizing Thesis itself. That’s why, Thesis has added it’s own set of Thesis hooks that makes modifying the theme very simple.

Lets solidify this with an example. Take the Thesis banner I’ve added to the top of the site. To do this, I first browsed through the Thesis hooks list and decided that thesis_hook_before_content would be the appropriate hook to use. You can also use the visual hooks reference at thesishooks.com which is a handy resource as well. Once we know which hook to use, open up your custom_functions.php file and add the following code.

function top_banner() { ?>
	<img src="http://thesisthemetutorial.com/images/thesis468x60.png"/>
<?php
}
 
add_action('thesis_hook_before_content', 'top_banner');

Add_action is a php function that takes 2 arguments, the hook name and a function. You can see I’m calling a function called top_banner and inside the function, all I’m doing is displaying my banner image. While this is really a trivial example, it really is this simple. By finding the appropriate Thesis hooks to use, you can pretty much customize the theme however you want.

No related posts.

Leave a Comment

Previous post:

Next post: