add_theme_support(‘my-custom-feature’)

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.

Read More

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(...)
}

Related posts

1 comment

  1. 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' )
                )
            );
    }
    

Comments are closed.