Thematic WordPress Theme Toolbox: 10 extremely useful hooks

by Jean. 23 Comments -

Do you like WordPress Theme Frameworks? To be honest, I’m a Thematic addict. Using this theme, I’m able to create any kind of site extremely fast. To help you getting started with Thematic child theme development, I have compiled 10 useful WordPress hooks in this article.

If you’re looking for a tutorial on how to create a Thematic child theme, you should read this post.

Add a favicon

A favicon is a small image displayed by modern web browsers. It is a must have for all websites, because it allows your visitors to quickly visualize your site among others when they have lots of browser tabs open at the same time.
This handy code will add your favicon to your theme. Make sure a favicon.png file is in your child theme images directory, and then paste the code in your functions.php file:

function childtheme_favicon() { ?>
	<link rel="shortcut icon" href="<?php echo bloginfo('stylesheet_directory') ?>/images/favicon.png" />
<?php }
add_action('wp_head', 'childtheme_favicon');

Source:

Add an Internet Explorer specific stylesheet

Who doesn’t hate Internet Explorer? Unfortunately, most clients will require developers to make their site IE-compliant. And the best way to do so is to use some conditional comments and a dedicated stylesheet.
Create a file named ie.css in your child theme directory, and then insert the following code in your functions.php file:

function childtheme_ie_style() { ?>
	<!--[if IE]>
		<link rel="stylesheet" type="text/css" href="http://www.webdevcat.com/wp-content/themes/webdevcat/ie.css" />
	<![endif]-->
<?php }
add_action('wp_head', 'childtheme_ie_style');

Modify Doctype

By default, Thematic outputs a XHTML 1.0 transitional doctype. If for some reason, you prefer using another kind of doctype, pasting the code below in your functions.php will do the trick.

function childtheme_create_doctype($content) {
 $content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
 $content .= "\n";
 $content .= '<html xmlns="http://www.w3.org/1999/xhtml"';
 return $content;
}
add_filter('thematic_create_doctype', 'childtheme_create_doctype');

Use Feedburner RSS feeds

Feedburner is very popular among bloggers. If you want to replace default rss feeds by feedburner feeds in Thematic, this code is for you.

function childtheme_rssfeeds($content) {
	$content = "\t";
	$content .= "<link rel=\"alternate\" type=\"application/rss+xml\" href=\"";
	$content .= "http://feeds2.feedburner.com/Catswhocode";
	$content .= "\" title=\"";
	$content .= wp_specialchars(get_bloginfo('name'), 1);
	$content .= " " . __('RSS feed', 'thematic');
	$content .= "\" />";
	$content .= "\n";
	return $content;
}
add_filter('thematic_rss', 'childtheme_rssfeeds');

Add Google Analytics code to your Thematic child theme

Google Analytics is another free and very useful service. In order to allow GA to collect your visitor information and create your stats, you have to insert a small piece of Javascript on your footer.php file.
Insert this code in your functions.php file, save it, and you’re done. Of course, don’t forget to replace the Google Analytics code with your own!

function ga(){ ?>
	<script type="text/javascript">
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	</script>
	<script type="text/javascript">
	try {
	var pageTracker = _gat._getTracker("UA-XXXXX-10");
	pageTracker._trackPageview();
	} catch(err) {}</script>
<?php }
add_action('wp_footer', 'ga');

Modify Thematic footer credit

If you’re building a Thematic child theme for a client, you may want to insert your credit link in the footer text. The following code will do it. Don’t forget to give credit to Ian Stewart for his awesome work on the Thematic theme framework!

function my_footer($thm_footertext) {
	$thm_footertext = 'Copyright &copy; 2010 Jean-Baptiste Jung. <a href="http://www.webdevcat.com">WebDevCat.com</a> is obviously powered by <a href="http://www.wordpress.org">WordPress</a> &amp; the <a href="http://www.themeshaper.com/thematic">Thematic Theme framework</a>.';
	return $thm_footertext;
}
add_filter('thematic_footertext', 'my_footer');

Display Thematic menu above header

Want to have your navigation menu above your site header? That’s not a problem. This code will remove the menu from below the header and then put it above it.

function remove_thematic_actions() {
    remove_action('thematic_header','thematic_access',9);
    add_action('thematic_aboveheader','search_access',9);
}
add_action('wp','remove_thematic_actions');

Change “more” link text

Thematic “Read More” link displays Read More » by default. The following code allow you to change the “Read More” text.

function childtheme_more_text($content) {
	$content = 'Click to read the rest!';
	return $content;
}
add_filter('more_text', 'childtheme_more_text');

Change gravatar size in Thematic comments

By default, Thematic displays 35px*35px gravatars. If you want to change this size, no problem: Just paste this code in, as usual, your beloved functions.php file.

function childtheme_avatarsize() {
    return '56';
}
add_action( 'avatar_size', 'childtheme_avatarsize' );

Source: http://themeshaper.com/forums/topic/on-using-avatars-in-thematic

Remove Thematic menu on specific page template

If you want to make a squeeze page on your site or blog using Thematic, that’s quite easy: You only have to create a page template and remove the menu. To do so, just paste the code below in your functions.php file.
Don’t forget to set your page template name on line 2.

function remove_access() {
    if (is_page_template('affiliate.php')) {
        remove_action('thematic_header','thematic_access',9);
    }

add_action('wp_head','remove_access');
}

Source: http://themeshaper.com/forums/topic/conditionally-removing-thematic_access

By the way, if you’re interested in Thematic Theme help, don’t hesitate to ask me. I just started freelancing and I’m ready to help you for a reasonable price.

  • http://www.scottcorgan.com Scott Corgan

    You nailed it! Why recreate it AGAIN. Ya, we need to innovate, but there are just some things that are so basic, that, well, they’re basic. So let’s innovate off of them!

  • http://www.letsgeek.net/ Harsh Athalye

    Great collection of hooks. IE-specific css and removing menu on specific page are especially useful. Thanks for sharing!

  • http://michaelsbrown.com/ Michael Brown

    Thanks for the post I really need to know this. It’s very informative.

  • Tim

    I’ll favorite this, very handy to use as a reference!

  • http://dougal.gunters.org/ Dougal Campbell

    Only half of those were specific to Thematic (doctype, feedburner, footer credit, menu above header, and remove menu for specific page), but still a handy list of tips for many people.

  • http://archondigital.com/ Archon Digital

    Another Thematic addict here! I really find it faster to work on websites using Thematic. Thanks for these hooks, they’re gonna make my life a lot easier.

  • Pingback: Quelques trucs pour Wordpress (2 &3) « Trois Point Zéro – Actualité, ressources, tutoriels autour du webdesign et du développement web en général

  • http://oldschoolscholar.com Q Ball

    Cats Who Code strikes again! I am a Thematic junkie, too!

  • http://www.y7ml.com y7ml

    Distinctive and useful article I put in my favorites
    Thanks!

  • http://www.comparecarinsurance4you.com Sean Golden

    Great hooks! Got to check them out. Thanks for sharing!

  • http://jeffsimpsonphoto.com/ Jeff Simpson

    solid work. I’m using a few of these on my upcoming blog

  • http://www.protectingyourchildonline.com Eloisa Luciano

    Cool stuff! WordPress created big questions for me since I first used it. Thanks for enlightening.

  • http://www.tomhermans.com Tom Hermans

    Great article Jean, gonna try these out in a couple of days.

    Although I enjoy coding themes ;) want to give thematic a go for once

    Tom.

  • http://www.fcswebsites.co.uk Nick

    Not tried Thematic yet but have been well impressed with Thesis and Atahualpa (if that’s how you spell it..) so will give it a go! Theme frameworks have let me extend WordPress beyond what I thought was possible and also deploy sites much quicker than hand coding.

    Nick

  • http://www.anekakita.com Aneka Kita

    Nice article..Very informative Many thanks!!

  • http://michaelsbrown.com/ Mich

    I just bookmark your link, thanks for sharing this

  • http://instructlearn.com Jerry

    Always great help from you buddy. Amazing articles and very clean coding and explanation. All those mods are extremely useful and can bring personality to wordpress.

  • http://www.blue2x.com blue2x

    Hi , awesome tips, will be using the favicon , move the menu above header and , read more text someday. Is there any difference if people use the feedburner feed or my default rss feed ? I also use feedburner

  • http://pippinspages.com Pippin

    The hook to move the navigation above the header is incorrect.

    The third line should be changed from

    add_action(‘thematic_aboveheader’,’search_access’,9);

    to

    add_action(‘thematic_aboveheader’,’thematic_access’,9);

    Great list!

  • http://www.borsarti.com/ borsa

    It’s very informative.

  • http://febriansyah.biz/ febri

    New thematic user here… ;)

    I got a question for you jean. Wich one better, thematic default IE class, or specific conditional comment like you wrote above?

    thanks before.

  • http://www.youtube.com/watch?v=W7OLifc4sGw Jamie

    Great hooks – very informative. You nailed it again! Thanks for sharing.

  • http://www.reiseversicherungen.info Heinz Rolf

    Thank you very much for your hints. I am using thematic since a while and made some child themes. But, nevertheless your hints have been extremely helpful.
    Good work Jean-Baptiste!!