0

According to the codex, there is no way that I can see to define a custom theme support feature.

Ideally, I'd like to set a feature in my child theme that the parent theme could check for.

Does an equivalent function exist that would be appropriate to use in this context?

For example, I'd like the parent theme to have a new sidebar in the header area, but since I'm introducing this sidebar area late, its presence could break previously created child theme layout look and feel.

So, for new child themes created after this addition, I'd like to be able to call something like:

add_theme_support('header-sidebar');

Then, in my parent theme, where I register the default sidebars available to any child theme, I'd like to use:

if(current_theme_supports('header-sidebar')){
 /* create a sidebar for the header area */
 register_sidebar(...)
}
3

You have to register the sidebars in the parent theme just late later enough. Use a hook that runs later, and child themes can register their theme support.

Child theme

add_action( 'after_setup_theme', 'register_header_sidebar_support' );

function register_header_sidebar_support()
{
    return add_theme_support( 'header-sidebar' );
}

Parent theme

add_action( 'wp_loaded', 'register_theme_sidebars' );

function register_theme_sidebars()
{
    if ( current_theme_supports( 'header-sidebar' ) ) 
        register_sidebar(
            array (
                'name' => __( 'Header', 'parent_theme_textdomain' )
            )
        );
}
  • 1
    Nice to know we can add arbitrary theme_support objects at will. That changes everything. – N2Mystic Feb 22 '14 at 16:14

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.