Child Themes A Pain In The Ass

Learning WordPress self hosted has been the most difficult challenge I’ve taken on in years. Since I’m not a rocket scientist, it takes at least three or four times reading and re-reading the tutorials before I think I’ve gotten it. In each tutorial there’s three or four crucial things I’ve never heard of, so I must do two or three more tutorials for each of those. Are you getting an idea of what I’m up against?

FolsomWknd 9-25-11 068 Child Theme a Pain adj v sf wm

Right now I’m struggling with “child themes”. Ever heard of php? And no you druggies, it’s not PNP, and not PCP.

PHP is one of the sub concepts I’ll need to do at least four more tutorials before I can get half a grasp.  WTF? Glance the following excerpt from the WP codex, and tell me it does not take a Stanford grad to finger it out?

Using functions.php

Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)

In that way, the functions.php of a child theme provides a smart, trouble-free method of modifying the functionality of a parent theme. Say that you want to add a PHP function to your theme. The fastest way would be to open its functions.php file and put the function there. But that’s not smart: The next time your theme is updated, your function will disappear. But there is an alternative way which is the smart way: you can create a child theme, add a functions.php file in it, and add your function to that file. The function will do the exact same job from there too, with the advantage that it will not be affected by future updates of the parent theme. Do not copy the full content of functions.php of the parent theme into functions.php in the child theme.

The structure of functions.php is simple: An opening PHP tag at the top, a closing PHP tag at the bottom, and, between them, your bits of PHP. In it you can put as many or as few functions as you wish. The example below shows an elementary functions.php file that does one simple thing: Adds a favicon link to the head element of HTML pages.

function favicon_link() {

echo ‘<link rel=”shortcut icon” type=”image/x-icon” href=”/favicon.ico” />’ . “n”;

}

add_action( ‘wp_head’, ‘favicon_link’ );

TIP FOR THEME DEVELOPERS. The fact that a child theme’s functions.php is loaded first means that you can make the user functions of your theme pluggable —that is, replaceable by a child theme— by declaring them conditionally. E.g.:

if ( ! function_exists( ‘theme_special_nav’ ) ) {

function theme_special_nav() {

// Do something.

}

}

In that way, a child theme can replace a PHP function of the parent by simply declaring it beforehand.

via Child Themes « WordPress Codex.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s