Problem: You’ve finally found a theme you like but you want to modify it. The modifications are pretty simple but what happens when you want to upgrade the theme? Do you really want to go through all those files again hunting down the changes? Don’t you wish you could just upgrade and be done with it?
I’ve been there. I’ve done everything the wrong way at least twice. Learn from my mistakes. Here’s the right way to modify your theme and protect it against any future upgrades. And don’t worry, it’s really simple. As it usually turns out, WordPress is ready for us and has done most of the heavy lifting.
Create a Child Theme for Simple Modifications
Did you know you can make CSS-only themes for WordPress? CSS-only themes pumped up with the power of custom PHP in functions.php? I don’t know why more people don’t know about this feature of WordPress or use it more often. It’s really powerful and clean and—more importantly—solves probably 99% of all your theme modification needs.
In wp-content/themes make a new folder called “sample”. Or “monstermonkey” or something. Try and make it unique. In that folder we’re going to make a file called style.css. Just like a regular WordPress theme. I’ll give you all the code for your style.css file straight up (adapted from the WordPress codex) and we’ll break it down afterwords. Here’s the code:
/*
Theme Name: Sample Theme
Theme URI: http://yourdomain.com/
Description: Testing WordPress Child Themes
Author: Your Name
Author URI: http://yourdomain.com/
Template: thematic
Version: 1.0
.
This work, like WordPress, is released under GNU General Public License, version 2 (GPL).
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
.
*/
@import url(../thematic/style.css);
a:link {
color:red; /* Red? Ugh! */
}
a:visited {
color:green; /* Green? Yechh! */
}
The most important thing in this stylesheet is Template: thematic. This tells WordPress to use all the template files from another theme. In this case Thematic. But it could just as easily be cutline, default, sandbox, or anything—as long as it matches the folder of the Parent Theme, all in lowercase. The WordPress codex calls this defining a Parent Theme. Thusly: Child Themes. You just made one.
Next we’re going to import the stylesheet of our Parent Theme. Thanks to relative links and WordPress naming conventions this is insanely easy.
@import url(../thematic/style.css);
The ../ is the most important thing here. It means move up one directory level. This gives us the power to import the stylesheet of any theme in our wp-content/themes directory. While this is fun for making weird theme mashups (try defining classic as your parent theme and importing the default stylesheet) the real power of this technique comes in protecting your favorite WordPress theme from upgrades.
You can now edit the CSS of your favorite theme without touching the original file. This is the real power of Child Themes. And it’s huge.
WordPress Child Themes are THE best way to make custom CSS changes to your themes.
In the example above I’ve made a pretty broad declaration about links changing the links to red (ugh!) and the visited links to green (yechh!)—as long as they don’t have very specific CSS declarations made in the original stylesheet. But what if you want to change the menu styles of your theme or the header styles, where more specific CSS declarations are made? This is easy too. Simply copy the offending section of the original theme stylesheet into your new Child Theme stylesheet and—boom!—you can make the changes there, free from worry.
Bonus for Thematic Users
If you want to start your Thematic Child Theme the exact same way I do, you’ll want to use the following code to start off your styles. It’s right out of the Thematic style.css, relativised for your Child Themes.
/* Reset browser defaults */
@import url(../thematic/library/styles/reset.css);
/* Apply basic typography styles */
@import url(../thematic/library/styles/typography.css);
/* Style the meta panel for logged-in users */
@import url(../thematic/library/styles/sitemeta.css);
/* Apply a basic layout */
@import url(../thematic/library/layouts/2c-r-fixed.css);
/* Prepare theme for plugins */
@import url(../thematic/library/styles/plugins.css);
/* Un-comment the line below to set a grid with 18px line-height to fit 125px ad units */
/* body { background:url(../thematic/images/960_grid_12_col.gif) repeat-y top center; } */
Bonus For Themes Built Up From The Sandbox
Scott and Andy’s beautiful WordPress theme impresses me once again. With the upcoming version 1.6 of The Sandbox (and consequently Thematic version 0.4+) you can modify parts of your Parent Theme by overriding it in your functions.php of the Child Theme.
Here’s one way to add a home link to your Sandbox 1.6+ or Thematic 0.4+ theme without touching the code of your parent theme at all. Make a file called functions.php in your child theme and copy the following code into it, between opening and closing PHP tags (“<?php” & “?>” ).
function sample_menu() {
$menu = <div id="menu"><ul>;
if ( is_home() ) {
$menu .= <li class="current_page_item"><a href=";
}
else {
$menu .= <li><a href=";
}
$menu .= get_option(home) . /" title="Home">Home</li>;
$menu .= str_replace( array( " ", " ", " " ), , wp_list_pages( itle_li=&sort_column=menu_order&echo=0) );
$menu .= "</ul></div> ";
echo $menu;
}
Now you’ve got a Home link in your menu! What else can you do? You can even add a changeable header using the WordPress Custom Image Header API. Check out this wiki article for more info on Child Themes (Scott calls them templates in his wiki).
Choose Plugins That Don’t Require Theme Modifications—Or Use The Right Kind of Theme
Confession time: I’m obviously completely comfortable with modifying WordPress themes but adding code for plugins and messing up my template files just rubs me the wrong way. It’s one more thing I have to worry about when I’m upgrading my site theme. If a plugin requires you to edit your WordPress theme reconsider that plugin. Is it really worth harming the upgrade-ability of your theme just to have that plugin?
Well, yeah. Maybe it is.
OK. Sometimes it is. But I have a solution. Use a different theme. Use a theme that comes ready for absolute must have plugins. Or a fully widgetized theme like Options, Vanilla or Thematic.
A plugin-ready parent theme takes the upgrade pressure off of you. Want Subscribe to Comments in your Theme? Thematic has it (until it moves to core—please!—move it to core!). Want to use Similar Posts in your theme after a single post? Thematic has a widget-ized area right after the single post. Just move the similar posts widget there.
It’s Really Not That Hard to Keep Your WordPress Theme Safe
Reconsidering the value of plugins, using a plugin-ready theme and using a fully widget-ized theme will make your theme upgrades a whole lot simpler. Add all that up with the power of Child Themes and you’re set.
source: themeshaper
Related Stuff
The Ultimate Wordpress SEO ChecklistHey everyone, I am back. This post is going to be about Wordpress SEO. It’s a checklist of the steps you should take to ensure that ...
Essential WordPress SEO PluginsSEO is a critical part of getting people to your site and these WordPress plugins help you acheive your goals quickly and ...
WordPress Configuration TricksMany WordPress users know the wp-config.php file as the key to the WordPress database. It is where you set the database name, username, ...
WordPress as a Comic Publishing PlatformThis post was spurred along by a comment at webcomics.com which has since been deleted, though I’ve been meaning to write something ...
8 WordPress Plugins to make your 404 error pages user friendly & efficient404 error pages are unavoidable, they creep in somehow no matter how well you build your site. But its normal. 404 error pages could appear ...

Original Source: