0

The reason why I ask such a question isn't because I don't know how to do so at all, but rather I think the way I've trying to go about it may be wrong and that I don't understand how wordpress works well enough to know what is the best way to add functionality and custom fields to an existing theme.

For example I have a theme for a website (a reverse auction project bidding theme) and a child theme was created so that of course changes could be made without changing the parent theme (for update/upgrade purposes). Now if I wanted to add a captcha box to an existing form, I know that I would have to change the files in the child theme (or use a plugin, which also requires a change to the file anyway).

Now this is the bit where I get a bit confused, I know that template files get overriden if you have the same file name in the child theme. But what if the file isn't a template file? I read on some other answers here that unfortunately they dont get overriden, and that coincides with what I've been doing (only modifying the file in the parent theme makes a change to the actual website). The issue here is that there are many pages on the website which use one template and these other pages are just coded as normal html/php files.

So my question can be asked in two ways, but I don't know which one is the right way: 1) If I wanted to add some php or html to these files (which can't be overriden), how would I do it. 2) or rather how can I get the file to be overriden in the child theme (when it is not a template file itself).

As you can tell, I'm a wordpress beginner so I reckon I'm missing something basic and fundamental about how everything works. To be honest I don't even know if this is the best way to go about making changes to a website, I'm new to all this and it seems odd to me that one would use wordpress to make a website that isn't a blog and also that in order to add functionality to a website you have to change the theme.

Sorry I haven't provided any code snippets, for one thing the theme was bought so I don't know whether I can show any of it, and secondly the question is more about concepts and the workings of wordpress.

P.S. sorry for the long post.

1

You also have a functions.php file which is really powerful in your child theme. You can override main theme functions, add new features - whatever you want. First thing I do in my child theme (usually) is add my google verification code.

function lmc_do_meta_tags(){
echo "<meta name=\"google-site-verification\" content=\"YOUR-CODE-HERE\" />";
}
add_action('wp_head', 'lmc_do_meta_tags');
0

First, you clearly understand the purpose of child theme : easier maintenance, speed up development. Your child theme inherits from its parent.

Your child theme can overwrite any file in the parent theme, you just have to name it the same way and the child file must be in the same directory, for example :

parent theme : css/icons/happy.css
child theme : css/icons/happy.css
  • Yeah, thats what I thought (the being in the same directory). I found a workaround but it may not be great. For example in my case the file i wanted to override (example name foo.php) which had just one function, and in the function.php of the parent theme it includes the file, for example include('foo.php'). But I think if the include is defined in the parent theme's function.php then it includes the foo.php of the parent theme. If I added include('foo.php') in the child theme's function.php then the function names would clash. So I had to rename the function in the child theme. – Cliff Sun Aug 21 '13 at 16:34
  • Depends on the quality of the parent theme. Most of the time I add a if(!function_exists('name_function') before my functions in my themes. This is handy for override because the child theme’s functions.php is loaded first. – JMau Aug 21 '13 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.