WP Theme Hackers

There’s nothing wrong with hacking WordPress themes. Not only is it a wonderful way to learn, but it can save you a bunch of time customizing your own theme. What I see all to often however, is not fully utilizing some of the wonderful shortcuts the WP core provides. For instance..

Say you want to add a special graphic, but don’t want to add it into WP’s built in media manager. All to often I see this..

<img src="http://domain.com/wp-content/themes/themename/images/myspecialgraphic.jpg" />

Sure that works fine but once you move your theme somewhere else that special graphic becomes broken! Try this instead.

<img src="<?php bloginfo('template_directory'); ?>/myspecialgraphic.jpg" />

Now many of you out there will find this elementary, but this is for those of you who starting out that don’t recognize this.. well this is to make managing your links much easier. That bloginfo('template_directory') template tag automatically links to your theme directory no matter where you move your files. And you should know that bloginfo() can be used for all sorts of things. I’m sure spotted it at the top <?php bloginfo('name'); ?> which displays the name of your blog. Or in the header.php file <?php bloginfo('stylesheet_url'); ?>, you guessed it! It adds a relative path to your stylesheet within your theme. WP themes are built on these tags and once you learn what is available you can really begin manipulating your site.

Check out the WordPress Codex for more information.

Posted: July 9th, 2011
Categories: Wordpress
Comments: No Comments.