Skip to Content
Menu

register_widget_areas()

Register various widget locations.

PHP June 27, 2018

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Widgets.php on line 15.

    1 Hook

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    "pre_register_widget_areas"
    Need a new filter hook? Request one here.

    Actions
    This function has no action hooks available. Request one?

    PHP
            public function register_widget_areas(){
                $override = apply_filters('pre_register_widget_areas', null);
                if ( isset($override) ){return;}
    
                //Sidebar (Primary) (Must be declared first!)
                register_sidebar(array(
                    'name' => 'Sidebar',
                    'id' => 'primary-widget-area',
                    'description' => 'The sidebar (primary) widget area',
                    'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
                    'after_widget' => '</li>',
                    'before_title' => '<h3 class="widget-title">',
                    'after_title' => '</h3>',
                ));
    
                //Header
                register_sidebar(array(
                    'name' => 'Header',
                    'id' => 'header-widget-area',
                    'description' => 'The vertical widget area that appears in the header',
                    'before_widget' => '<div id="%1$s" class="row widget-container justify-content-center"><div class="col align-self-center %2$s">',
                    'after_widget' => '</div></div>',
                    'before_title' => '<h3 class="widget-title">',
                    'after_title' => '</h3>',
                ));
    
                //Hero
                register_sidebar(array(
                    'name' => 'Hero',
                    'id' => 'hero-widget-area',
                    'description' => 'The horizontal hero widget area',
                    'before_widget' => '<div id="%1$s" class="col-md widget-container align-self-center %2$s">',
                    'after_widget' => '</div>',
                    'before_title' => '<h3 class="widget-title">',
                    'after_title' => '</h3>',
                ));
    
                //Single Post
                register_sidebar(array(
                    'name' => 'Single Post',
                    'id' => 'single-post-widget-area',
                    'description' => 'Appears after a single post article.',
                    'before_widget' => '<div id="%1$s" class="row widget-container"><div class="col %2$s">',
                    'after_widget' => '</div></div>',
                    'before_title' => '<h3 class="widget-title">',
                    'after_title' => '</h3>',
                ));
    
                //Footer
                register_sidebar(array(
                    'name' => 'Footer',
                    'id' => 'footer-widget-area',
                    'description' => 'The horizontal footer widget area',
                    'before_widget' => '<div id="%1$s" class="col-md widget-container %2$s">',
                    'after_widget' => '</div>',
                    'before_title' => '<h3 class="widget-title">',
                    'after_title' => '</h3>',
                ));
            }
    

    Override

    To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

    PHP
    add_filter('pre_register_widget_areas', 'my_custom_register_widget_areas'); 
    function my_custom_register_widget_areas(){ 
        //Write your own code here
    
        return true; //Return true to prevent the original function from running afterwords
    }

    You can completely disable this PHP function with a single line actions:

    PHP
     add_filter('pre_register_widget_areas', '__return_false');