Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove Wordpress theme options from child theme

I start new projects by writing a child theme for the twentyeleven theme. I rarely design the new theme to use any of the options built into the twentyeleven theme (such as background color, etc). Those residual options don't really hurt anything, but I'd like to get rid of them since they don't do anything.

The trouble is that the theme options are declared in the parent theme's functions.php, which is loaded along with (not instead of) the child theme's functions.php file (so I could delete them but they'll come back next upgrade).

Is there a way to remove or disable those theme options from my child theme? Perhaps something along the lines of a "remove_options()" function? Or perhaps something that would achieve that effect? In other words, the question is whether theme_options can be removed WITHOUT deleting/overriding the original function that added them.

I'm sure with enough puttering, I could hide the option with CSS or javascript... but c'mon.

like image 416
emersonthis Avatar asked Jan 24 '12 22:01

emersonthis


People also ask

How do I override a WordPress child theme?

If the function you want to extend is pluggable, copy it into your child theme and add extra code to extend it. If the function isn't pluggable, remove it from its hook using remove_action() and write a new function (with a different name) on the same hook with extra code.

What is the difference between WordPress theme and child theme?

A child theme is an add-on for your existing WordPress theme A child theme, as defined by the WordPress Codex, is a theme that “inherits the functionality and styling of another theme, called the parent theme.” Child themes are recommended to modify existing themes while still maintaining their design and code.

Can you remove themes from WordPress?

In your WordPress site, go to Appearance > Themes. You'll see all of your installed themes displayed with the active one first in the list. From the list, click on the theme you want to delete to view its details. In the lower right-hand corner, there's a Delete link.

Should I activate child theme or main theme?

You need a child theme if you want to change files of your theme. If you have to make a lot of CSS adjustments, there's no better way than having a decent editor right in the style. css. It is equal if you constantly have to insert new code for your functions.

Can you delete a parent theme WordPress?

Go to Appearance → Themes and click on the My Themes tab (visible only plugin-enabled plan sites.) Click the ellipsis (three dots) to the right of the theme name to open up the theme options. Select Delete.


1 Answers

After a second round of digging...

This is TOTALLY easy!

You can retrace my steps by starting here, but the code is pretty self-explanatory:

add_action( 'init', 'remove_crap' );
    function remove_crap() {

    remove_custom_image_header();
    remove_custom_background();
    remove_theme_support('post-formats');
}

You can look these up in the codex. Remove_theme_support takes one of several strings that identify various options (besides just post-formats). The only issue I encountered is that they need to be called from a hook (you can't just dumpt them into functions.php). I'm using init but there's probably another one that's more appropriated.

The only thing I still haven't figured out is how to remove the "Theme Options" page link that appears under Appearances. I know it's added with add_theme_page() but there doesn't seem to be a handy remove_theme_page().

UPDATE: I found it! This is VERY poorly documented, but in the end it's quite 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, 'themes.php' targets the Appearances menu and 'theme_options' is the menu_slug used in the twentyeleven theme. Obviously these parameters will differ depending on which menu or submenu you're editing. This page will point you in the right direction.

ps: Here's how to get rid of templates from the parent theme that you don't want to use: THIS isn't essential to my exact question, but it's closely related and probably useful to anyone who's trying to do what I'm doing.

like image 129
emersonthis Avatar answered Oct 03 '22 14:10

emersonthis