Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Child theme: three questions WordPress

Wp version: 3.4.2
Theme: Twenty Eleven

First question:
how can deactivate functions in a child theme
(for example comments in comments.php or some functions in functions.php)?

Second question:
If i'm going to change a function (for example changing text or adding a parameter)
does the parent theme with original function will overwrite it?

Third question:
In the Wordpress codex this is code siggested to include files in child theme:

require_once( get_stylesheet_directory(). '/my_included_file.php' );

Where i've to put this line of code? In the parent functions.php?

And if i've to include many files in the child theme (e.g. 404.php., comments.php., content.php etc.) i've to write this line of code multiple times?


Answers (5)


Kyle answers:

1 & 2) The point of child themes is that you can override everything in the parent theme without altering it. So you can play with the functions and comments files as you want. To deactivate it you can remove it from the child theme comment or functions file. If you want to deactivate something from the parent theme, you can remove the action by place something like

remove_action('action_in_parent_theme', 'function_in_parent_theme');

3) That kind of code goes in your child theme functions file. The get_stylesheet_directory() call will always direct to the currently activated theme folder.

Hope that helps :)


phppoet answers:

To remove functions simply remove all function name with its code .

just like my_function() {


and to rename function simply change name of the function . also rename the function into the code where it is being use .

like my_new_function {
echo "hello world";



to include files simply use this function

include ('new-file.php'); or
include_once ('include/new-file.php '); // to include new-file.php from include folder .

you can also use require in place of include . depend on the need. You need to learn basics of php . Youtube video tutorial would be a great resources .

best luck .

maryhellen comments:

If I have more more than 1 file to include i have to write this code multiple times like this example?

include ('new-file1.php');
include ('new-file2.php');

phppoet comments:

yes you can include as many file as you want in this way.

for example '


and your desired function into included files .

phppoet comments:

you can contact me on skype if you want more help

skype id : phppoet

i will try to clear your basics


Francisco Javier Carazo Gil answers:

Also use: require_once and include_once to avoid problems loading functions two or three times.

And use this also to prevent redefine functions:
function mi_function()
/* */

maryhellen comments:

So to include three files i'have to use this code:
require_once( get_stylesheet_directory(). '/my_included_file1.php' );

require_once( get_stylesheet_directory(). '/my_included_file2.php' );

require_once( get_stylesheet_directory(). '/my_included_file3.php' );

Is this the correct way?

Francisco Javier Carazo Gil comments:

Yes you can do it or if you prefer as Arnav says use functions.php and include in this file all functions to use the WordPress standard way.


Arnav Joy answers:

to include file or multiple files you can include them in child theme's functions.php only once and they will called in every standard file of wordpress theme

maryhellen comments:

What i want to achieve is include almost all parent theme same pages but with different code to create a child theme without build a new theme from scratch. so, for example, include 404.php without a function or content.php with a lisght different code to customize layout, html tag and so on.

So are you suggesting to take all this different changed code from different pages and put in the unique functions.php?
Does in this case code in this new file will overwrite all the code in the theme original pages ( e.g. 404.php, sidebar.php content.php etc.)?

Arnav Joy comments:

sorry but i am not clear with your last points...

maryhellen comments:

I mean that i can put all the code, now in the different pages ( 404.php., content.php. etc.), in one functions.php file
and code in this file will overwrite all the other functions?


Naveen Chand answers:


functions.php is primarily meant to store php and wordpress functions. The other php files that you are talking of can be recreated into a child theme by creating a new file with exactly the same name in your child theme directory. For example, if you want to edit 404.php that appears in your parent theme, then create a new file in your child theme directory with exactly the same name as "404.php" and start editing in this. Infact you can copy the file from parent directory and paste it in child directory and start editing the code.

Wordpress gives your child theme files the highest priority while loading your site.

So I would suggest better copy all the files you want to edit into your child theme (also following the same sub-directory structure, if any existing in parent directory). This is the right way to include the files from your parent directory.

So what happens if you have not copied some files? Wordpress tries to find if such file exists in your Child directory. If not, it will go to the Parent directory and use that file. So you do not have to necessarily copy every file. Copy only those which you want to edit.

Hope this helps.

maryhellen comments:

Thanks a lot. So i can put every functions also present in page files (e.g. 404.php. content.php, sidebar.php etc.) in a unique funcion.php file in the child theme?

Naveen Chand comments:

Yes you can do that @maryhellen. Copying the functions from any of these pages, into your child theme's functions.php will be enough. You can then edit the function you've copied. Ideally, copy only those functions which you want to edit. If you don't need to make any edits, then leave them as they are in the parent directory. Wordpress accesses functions from your parent theme that do not conflict with your child theme. Whereever there are conflicts, it will give your child-theme the first priority.

maryhellen comments:

Thanks for clarifications. So now i'm in doubt: if i want create a totally new theme from Twentyeleven and named
differently, does the child theme is the best choice or maybe it's best to renamed twntyeleven theme and create a new theme form it changing its code?

maryhellen comments:

Thanks for clarifications. So now i'm in doubt: if i want create a totally new theme from Twentyeleven and named
differently, does the child theme is the best choice or maybe it's best to renamed twntyeleven theme and create a new theme form it changing its code?

Naveen Chand comments:

You can do either way - copy the folder and rename and use it or create a child theme. I would strongly recommend creating Child theme as it is the best choice. Let me explain you why?

A child theme inherits everything from the parent theme. Whenever a parent theme gets updated, your website or part of your website will not break because the functions and edits made in child theme will be untouched. Not only that, you can safely enjoy the benefits of the updates of the parent theme while still using you custom made child theme. It has its own advantages.

On the contrary, creating a new copy of twentyeleven theme means you are on your own. The theme will not get updated because you would have changed the folder name and several other files.

One should always look out for a regularly updated theme so that it keeps itself compatible with wordpress upgrades or php upgrades or database upgrades.

Hope this advice helps. In case you need help with creating a basic child theme from twenty eleven, please feel free to write to me at [email protected]

Alternatively, Wordpress Codex gives excellent tutorials on developing child themes.

maryhellen comments:

Thanks. Last question: can i rename child theme directory? I need to have a theme with client website name. Thanks again for your time and patience.

Naveen Chand comments:

Ofcourse @maryhellen. Infact you must have a unique theme directory name. So you must change the directory name.

Naveen Chand comments:

Also, you have an option to give a unique Name to your child theme apart from changing the directory name. Here is how you do it:

In your Child Theme, this is how your style.css file must begin:
Theme Name: Twenty Twelve Child Theme Name
Theme URI:
Description: Child theme for the Twenty Twelve theme
Author: Your name here
Author URI:
Template: twentytwelve
Version: 0.1.0

In the above code, you can change your theme name in the very first line.

IMPORTANT: Do not change the word in the <strong>Template:</strong>. This is essential for your child theme to be linked to the parent theme always. This is the actual folder name of your Parent Theme Directory.

Hope this helps.

maryhellen comments:

Thanks. I will change both: child theme name directory and child theme name in the style sheet.