How to remove Wordpress theme options from a child theme

I am launching new projects, writing a children's theme for the theme of twenty. I rarely develop a new theme to use any of the parameters built into the twentieth theme (for example, background color, etc.). These residual options do not actually hurt anything, but I would like to get rid of them since they do nothing.

The problem is that theme parameters are declared in the parent functions.php theme, which is loaded along with (and not instead of) the child theme functions.php file (so I can delete them, but they will return to the next Update).

Is there a way to remove or disable these theme options from my child theme? Perhaps something like the remove_options () function? Or perhaps something that achieves this effect? In other words, the question arises whether theme_options can be deleted WITHOUT deleting / overriding the original function that added them.

I'm sure with enough rhyme, I could hide the parameter using CSS or javascript ... but c'mon.

+7
source share
4 answers

After the second round of digging ...

It is TOTALLY easy!

You can restore my steps by running here , but the code is pretty clear:

add_action( 'init', 'remove_crap' ); function remove_crap() { remove_custom_image_header(); remove_custom_background(); remove_theme_support('post-formats'); } 

You can see them in the code. Remove_theme_support accepts one of several lines that identify various parameters (in addition to only post-formats). The only problem I encountered is that they need to be called out of the hook (you can't just sketch them on functions.php). I use init , but maybe another one that is more assigned.

The only thing I still do not understand is to remove the link to the Theme Settings page, which appears in the Appearances section. I know that it was added using add_theme_page() , but there seems to be no convenient remove_theme_page() .

UPDATE: I found it! This is VERY poorly documented, but in the end it's pretty easy to do:

 add_action('admin_init', 'remove_twentyeleven_theme_options', 11); function remove_twentyeleven_theme_options() { remove_submenu_page('themes.php', 'theme_options'); } 

In my example, theme.php targets the Appearances menu, and theme_options is the menu_slug used in the twenty-one theme. Obviously, these options will differ depending on which menu or submenu you are editing. This page will point you in the right direction.

ps: Here, how to get rid of templates from the parent theme that you do not want to use: THIS is not essential for my exact question, but it is closely related and probably useful for everyone who is trying to do what I do.

+12
source

The correct way to remove support for a theme added to a parent theme from a child theme is to call remove_theme_support as a result of the after_setup_theme action with a lower priority than the parent.

The functions.php file from the child themes is called immediately before the parent theme, so if you use the default priority for after_setup_theme, the after_setup_theme child ends up being called in front of the parent, so you end up removing non-existent theme support in your child, only to it was added back from the parent running after_setup_theme.

So, by adding a child action with a lower priority, you can make sure that it is called after calling the parent call to the same action.

So:

 // added to child functions.php add_action( 'after_setup_theme', 'child_after_setup_theme', 11 ); // Parent theme uses the default priority of 10, so // use a priority of 11 to load after the parent theme. function child_after_setup_theme() { remove_theme_support('custom-background'); remove_theme_support('custom-header'); remove_theme_support('post-formats'); // ... etc. } 

In the case of twenty-one threads, you can also just drag the entire twentyeleven_setup function into the .php child functions, but this is a pretty inaccurate method to achieve this.

+8
source

Unfortunately, the way to use theme inheritance in Wordpress is that the child functions of the theme are simply added to the parent functions of the theme.

Unlike style.css, function.php of a child theme does not override its copy from the parent. Instead, it loads in addition to the functions.php parents. (In particular, it is loaded immediately before the parent file.) (1)

So, in the direct answer to your question above, it looks (2) how this might not be possible with the way WordPress handles themes and children's themes.

Personally, I would not worry about these additional functions or variables in the functions.php file.

+1
source

This is an old thread, so I just want to add if someone enters this place and wants to get an answer. I solve the child theme, take the exact file, making a copy and adding it to the child theme. I have a plug-in "advanced code editor", so I do not need to go through FTP. Copy the file you want to edit, create a new sheet in the child theme with the same name and content, and then make the necessary changes. It will first download the child theme files and your site will be updated.

+1
source

All Articles