Lost? Yes lost. Even though I was reading how to make a child theme, I had no way to put it into practice and I didn't have a reason to do so. It wasn't until I learned the reason for making a child theme and until actually attempting to do so, that I was found.
I had a client that wanted to use a specific theme for their site. They just wanted modifications made as is expected. I wanted my client to be able to manage their own website for as long as possible after my work was done. This might be the wrong strategy for my bank account but I like to give the customer what they 1. Need, 2. Want, and 3. Pay for. And I hope to have customers that return because they want to, not because they have to. But I digress.
In order to prevent my work from being overwritten during an update I searched for a way to keep my modified files separate from the original theme. This is where I found The Purpose. Let me write this clearly. What is the purpose of a child theme? The purpose for creating a child theme is to make changes to an existing theme that will persist throughout future updates to that theme.
The Client reaps all the rewards for having a theme modified in this way. The clint has probably paid for the original theme and was likely promised new features and patches in the form of future updates. The client will be notified of these updates by the original theme developer and will likely want to install those updates. Who wouldn't? New = Awesome and Exciting! By telling your client "Don't update this theme or all the customization will disappear" you are removing value from the theme. And you know they're going to forget anyway and click the button when it shows up. You could disable the updates by changing the theme such that it doesn't recognize itself anymore, but that's just cruel, and again you are removing value from the original developer's work.
I though making a child theme would be complex. It's not.
Allow me to explain how things work before sending you to the codex to look at the actual code. To make a child theme, you just make a new theme folder, as if you were creating a new theme and start with a style.css file. In that file you use some special syntax that Wordpress understands and basically tell Wordpress where to find all the files it needs. You can add styles if you wish at this point which will load after the original styles. In fact, all of the files that you create in your new child theme will work similarly to this. They will load either along with (after) their counterparts in the original theme or instead of them.
For example, let's say we make our style.css file, write the necessary code and then we make a page.php file in the same directory. When a page is loaded in Wordpress, your new page.php file will be used instead of the one in the original theme's folder, while everything else will be loaded from that parent(original) theme. The header, the footer, the functions... everything that would have been loaded if you had the parent theme active will load as if that theme were active. If you make a functions.php file and add code to it, it will load along with the parent theme's functions.php file (so make sure not to duplicate functions as it will cause php errors).
You must put files in the same directory structure as the parent theme if you wish them to be used in place of those original files. If an include is set to retrieve /js/some_crazy_script.js and you wish to modify that file, create a "js" directory and either copy the file from the parent theme and modify it, or create a new one with the exact same name and write it differently. Wordpress will then use your version of some_crazy_script.js instead of the original file.
Fairly straight forward. The trick is knowing which files are instead and which files are loaded along with the parent theme's versions of those files. Most use the "instead of"method, I believe. It also helps to know if the files are being loaded before or after the parent theme's version of that file.
To begin making your own child theme visit the Wordpress Codex - Child Themes.
No comments:
Post a Comment