WordPress 3.3 Could Improve Child Theme Integration

According to a recent WordPress trac ticket, theme authors could soon be rewarded with a little nugget of functionality that would make using child themes much more extensible.

The ticket suggests introducing a function that works similarly to locate_template(), but rather than returning the path of the file (in the parent theme only), it would return a URI to the file, thus allowing a child theme to override the parent’s .js, .css and even image files. The proposed function is called locate_theme_file().

According to the suggested patch posted by johnbillion, this is the current method for loading template files in parent themes only:


wp_enqueue_style( 'dark', get_template_directory_uri() . '/colors/dark.css', array(), null ); 

If locate_theme_file() is introduced, we could instead see functions like these:


wp_enqueue_style( 'dark', locate_theme_file( 'colors/dark.css' ), array(), null ); 

wp_enqueue_style( 'bar', locate_theme_file( 'bar.css' ) );

<img src="<?php echo locate_theme_file( 'icon.png' ); ?>" />

locate_theme_file() would automatically load any of these files via the child theme, BEFORE the parent. Pretty neat huh?

Up to this point, child themes could only override a parent theme’s template files. If theme authors are rewarded with the ability to enqueue many more types of files at the child theme level with this much ease, I anticipate seeing some really exciting new uses for child themes emerging.

How to Make SiteLauncher Work With Firefox 5

Being a Web-worker, I rely on my browser to provide the tools I need to work quickly and efficiently. And since I’m an avid Firefox user, the last couple of months have been fraught with turmoil because I was torn between staying with the trends and updating Firefox (first from 3.6 to 4, then recently from 4 to 5) and waiting for the developers of all of my add-ons to keep up.

I waited and waited and waited to upgrade Firefox to version 5 because I was holding out for the developer of SiteLauncher, to be updated. SiteLauncher is integral to my workflow, because it allows me to open specific webpages using preset keyboard shortcuts.

Turns out, I didn’t need to wait.

Thanks to the folks over at The Heat Web, making SiteLauncher 2.1.0 compatible with Firefox 5 was as easy as changing a value in a file.

There are two ways to do this:

1) The Easy Way

» Download/install this (already modified) file sitelauncher2.1.0.xpi and restart Firefox

2) The Hard-er Way

» Visit the SiteLauncher Download Page, right-click the Add SiteLauncher to Firefox button and click Save As. Save sitelauncher2.1.0.xpi to your hard disk.

» Open the directory where you saved sitelauncher2.1.0.xpi and change the file extension to .zip (sitelauncher2.1.0.zip)

» Important: Open the .zip file in your archival software. DO NOT UNZIP THE DIRECTORY.

» Right click on install.rdf and open it in NotePad (or TextEdit on Mac)

» Locate the maxversion value and change it from 4.2alpre to something above 5. I changed mine to 5.9.9 to make it compatible all the way to Firefox 6.

» Save install.rdf and update the archive

» Back in the directory where you saved the original file, change the file extension back to .xpi from .zip

» All you have to do now, is drag the sitelauncher2.1.0.xpi file over to your Firefox window and it should prompt you to install the add-on.

» That’s it!

Update: Though this hack makes your SiteLauncher keyboard shortcuts work, you’re still unable to modify or add new shortcuts via the backend menus. Thanks Steven!

Add something to post title based on post type

Recently, I was working on a WordPress install employing several custom post types to handle two separate “blogs” within a single site. The site used normal ‘posts’ to handle articles and the client wanted to append the word “BLOG” to the beginning of blog posts’ titles only.

Using the Codex I slapped something together rather easily.

Using the following snippet, I built a simple if statement to test for blog posts, and if not, to render the_title() minus any extra text.

// First test for the post type(s)
<?php global $post
if (get_post_type($post) == 'post_type_1') || get_post_type($post) == 'post_type_2') { ?>
// IF either test registers true, then set the $before parameter in this format: the_title($before, $after);
<h1><a href="<?php the_permalink(); ?>"><?php the_title('BLOG: ', ''); ?></a></h1>
// IF not, then display as normal
<?php } else { ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
// Close the IF statement
<?php } ?>

Using this example, posts that register as true would display like this:

BLOG: The post title