Removing custom background and header feature in child theme

I am creating a child theme using twentyten as my base. I am looking for a way to remove the features of adding custom header and background without touching functions.php file in the parent theme.

no luck with this 🙁

function my_child_theme_setup() {
    remove_theme_support('custom-background');
    remove_theme_support('custom-header');
}

add_action( 'after_setup_theme', 'my_child_theme_setup' );

Related posts

Leave a Reply

5 comments

  1. Both the header and background image features setup some globals in order to work, unsetting those globals seems to have some effect, and at the least removes them from the administration side.

    add_action('after_setup_theme', 'remove_theme_features', 11 );
    
    function remove_theme_features() {
        $GLOBALS['custom_background']   = 'kill_theme_features';
        $GLOBALS['custom_image_header'] = 'kill_theme_features';
    }
    class kill_theme_features {
        function init() { return false; }
    }
    

    There’s expectations for a class name to be provided as a callback for both of these features, and both expect the given class to have an init method. The solution was to create a dummy class that does nothing and update the globals, which effectively kills off the theme background and header pages in the admin area.

    Hope that helps..

  2. Child theme is processed before parent theme. So your function is getting hooked earlier and fires before twentyten_setup().

    Try:

    add_action( 'after_setup_theme', 'my_child_theme_setup', 11 );
    

    Alternatively you can copy twentyten_setup() to your child theme and modify, since it is declared conditionally on ! function_exists( 'twentyten_setup' )

  3. remove_theme_support should do the trick.

    EDIT-

    It seems custom headers & custom backgrounds have their own functions for this: Custom Headers . I assume the same type of function should be for custom backgrounds, but I can’t find it in the reference, searching for it in the files.

    EDIT 2 –

    The remove_custom_image_header function is available only from 3.1, according to the codex. I would suggest Rarst’s suggestion right now.

  4. try:

    function my_child_theme_setup() {
        global $_wp_theme_features;
        unset( $_wp_theme_features['custom-background'] );
        unset( $_wp_theme_features['custom-header'] );
    
    }
    
    add_action( 'after_setup_theme', 'my_child_theme_setup' );
    

    Hope this helps

  5. From a brief search through core, i couldn’t verify the existance of remove_custom_image_header() *). I only found add_custom_image_header() that uses add_theme_support(), so this should work.

    If it doesn’t you can go one step closer to core and use the Theme Modifications API. Strange as it is: The API only has a function that removes all modifications: remove_theme_mods() that takes no additional parameters.

    After thinking about it, your best chance is to filter it: add_filter( "theme_mod_$name", 'your_callback_fn' );, but i’m not completely sure if it removes it from admin UI (10% chance it does). So maybe you’ll have to unset that menu entries via another function.

    Anyway: Take a look into ~/wp-includes/theme.php … that’s the “twenty ten” core support file (that won’t be used by other themes i guess).

    *) This is really strange…

    Edit:

    remove_custom_image_header() now is available with WP 3.1+.

    And a short edit of @t310s answer:

    function remove_theme_features() 
    {
        $GLOBALS['custom_background']   = '__return_false';
        $GLOBALS['custom_image_header'] = '__return_false';
    }
    add_action( 'after_setup_theme', 'remove_theme_features', 20 );
    

    It’s just shorter.