Add Extra Widget Areas to Thesis

by admin on April 13, 2010 · 21 comments

Add Extra Widget Areas to Thesis

Thesis is a wonderful theme framework, but one of the things I find it lacks is widget areas. Luckily, it’s incredibly easy to create more. First I’m going to show you the code you need to place in your custom_functions.php , and then I’ll explain it all.

The Code

<?php

add_action('thesis_hook_after_header', 'afterheader');
function afterheader() {
?>

<div id="afterheader">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('afterheader') ){ ?>
<?php } ?>
</div>
<?php
}
?>

<?php
register_sidebar(array('name'=>'AfterHeader', 'before_title'=>'<h2>', 'after_title'=>'</h2>'));
?>

The Explanations

That’s not so scary, is it? Nope. Just a few lines of code, really. Here’s what these lines do:

<?php

add_action('thesis_hook_after_header', 'afterheader');
function afterheader() {
?>

This begins registering the function. When customizing Thesis themes you’ll see these lines a lot. First we explain where the widget will end up on the page and then we name it.

<div id="afterheader">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('afterheader') ){ ?>
<?php } ?>
</div>
<?php
}
?>

This creates the sidebar and is not Thesis-specific; it’s a WordPress function. We wrap the widget in a div for easy customizing later.

<?php
register_sidebar(array('name'=>'AfterHeader', 'before_title'=>'<h2>', 'after_title'=>'</h2>'));
?>

This is also a WordPress function. These lines register the widget and then close off our function. We name the widget, which is what you’ll see in your Widget Options Pnale, and then we wrap the title in an h3 tag to match the other sidebars.

More Widgets, Hooks, etc.

You can do this as many times as you’d like. Just make sure to change all instances of “afterheader” to something that describes the additional widgets.  There are tons of hooks available for Thesis that you could place your widgets in. Check out the full list here.

If you’d like to put widgets in your footer, Asnio has done a free mod you can download here.

Happy widgeting.

photo by Riebart

Previous:

Next: