The power of Thematic hooks

HTML, Web 2.0, Web Development No Comments

As I begin to wrap up my first child theme using the Thematic framework, I must admit that I’m beginning to really appreciate the power of theme hooks. At first I was modifying the css to get where I wanted to be, for example altering margins, using the background url directive to add my custom header image. But when I got to the point where I wanted to suppress the display of the blog title and description, that is when I first found out about Thematic add and remove actions.

Oh sure I could have just used “display: none” in the css blog title class/ids so that the blog title didn’t display over my custom image, but that’s kind of ugly. Using remove_action in my functions.php file is much more elegant.

function suppress_header_elements() {
remove_action('thematic_header','thematic_blogtitle',3);
remove_action('thematic_header','thematic_blogdescription',5);
}
add_action('init','suppress_header_elements');

And the bonus is that the blog title description value still populate my title and meta description tags as desired for SEO optimization.

Theme hooks is not a concept unique to Thematic but embedded in Wordpress itself. Using theme hooks in your child theme, the idea is that you can isolate your customizations in a single file in a functions.php file (it may be called something different such as custom_functions.php with other frameworks).

Although I had altered the css to add my image, I wanted to additionally add clickable button images as well that I already had defined in a css file. No problem, I just created a new function called add_buttons in my functions.php file, echo’ed out the HTML and then added the add_action line:

function add_buttons() {
echo ....
}
add_action('thematic_header', 'add_buttons');

It wasn’t completely smooth sailing as I ran into this error when I tried to use the admin (error text modified to remove site identifying info)

Warning: Cannot modify header information - headers already sent by (output started at /home/mysite/public_html/blog/wp-content/themes/childtheme/functions.php:43) in /home/mysite/public_html/mysite.com/blog/wp-includes/pluggable.php on line 865

Most of the information you get googling this error suggests there is extra spaces prior to the php start tag in the wpconfig.php file. That wasn’t the case here, but it was a good clue. Turns out I had an extra blank line after the closing php tag in my functions.php file. When I finally figured out to remove that, the errors went away.

wordpress theme frameworks, thematic

Web Development 1 Comment

After poking around at both Hybrid and Thematic, wordpress frameworks, I went with Thematic. The reason? Better documentation. I followed Hybrid’s instructions on installing a child theme and and got a broken theme. I was more successful with Skelton, but felt overwhelmed by the amount of work I need to do in css land to get to a reasonable looking theme. So in the end I installed Thematic which has some basic layout css files prepackaged to get you started with your child theme. Of course my decision to go with Thematic may reflect some learning challenges on my part, but in the end, Thematic got me quicker to where I needed to be.

Note this project is for a separate blog, not this one. The cobbler’s children makes do with last year’s shoes.

A bit more on frameworks and why you should care. Using a WP framework gives you some separation between functionality and presentation, always a worthy goal. And it allows you to subclass (well kind or) distinct functional components while preserving the ability to upgrade the originals. What I mean by this, is that you can copy a php file (say header.php) from the parent theme to your child theme directory and alter the copy. Wordpress, in it’s later versions, knows to look first for the php files in the child theme. The idea here is that when wordpress and the parent theme is upgraded, there is some insulation … I’ll let you know how that goes when I get there.

I mentioned that I went with Thematic because of the better documentation. It took a little digging, but this tutorial series of blog posts are really helpful to get you started. I particularly appreciated the pointer to a sample xml file you can import into your theme to help QA it and review all the little styles you might want to customize. That in itself was a nice find.