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.

Firefox and IE and tag conflicts

HTML No Comments

I have been doing some customization to the wordpress theme I have using for this blog.  The original theme was too mono-colored and the link color was hard to see.  And of course I wanted my own header.

Many blog themes put the title of your blog both as the page title tag and also as a H1 somewhere as text in your header.  This was fine with me but I wanted to have it display in a smaller font size to be more compatible with my custom header and not overrun my graphic.

So I went into the css of the blog theme and found the id tag (called “h1″) that specified the size in “em” and picked a smaller size.

It looked great on firefox, but on IE7 the size was unchanged.   Furthermore I had also changed the link color from a barely distinguishable grey to a dark red with a command to underline the link on hover.   Again worked great on Firefox 3, totally ignored on IE7.

With some help from my webdesigner friend from talksure, we figured out the problem.   For the blog title, the theme not only enclosed the text in a div tag specifying the id “h1″, but it also had additionally enclosed the text in h1 tags (confusing .. but they *are* different).   Of course the css had a larger size specified for the h1 tag. What was happenning was Firefox gave the div tags priority .. but IE7 gave the regular h1 tags priority.

A similiar problem explained the link color problem.

If you have conflicting tags, the behavior by IE and Firefox is likely to be different.

We think the reason that the title was enclosed in both a div tag and a h1 tag was to give the search engines a recognizable H1.  And it makes sense this would be the blog title.  However for now, the H1’s are removed so that my blog looks the same on all browsers.