Register and Display Widget Area In Wordpress

<?php
/**
* Register Widget Area.
*
*/
function wpgyan_widgets_init() {
    register_sidebar( array(
        'name' => 'Header Sidebar',
        'id' => 'header_sidebar',
        'before_widget' => '<div>',
        'after_widget' => '</div>',
        'before_title' => '<h2 class="rounded">',
        'after_title' => '</h2>',
    ) );
}
add_action( 'widgets_init', 'wpgyan_widgets_init' );
?>
Paste this code into your theme's functions.php file. Now you could see widget area into site backend navigating Appearance -> Widgets..


Now you could place Widgets on this widget area using available widgets.

DISPLAY WIDGET AREA

Once you have added content. Now you could show this widget area on required position in theme layout using following Code.

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('header_sidebar') ) :
endif; ?>

Now you could see widget content on your site.


Cheers!!!
 

Comments

Popular posts from this blog

Create New Project in Laravel

How to Get Access of Database of Dynamic Site Without cPanel Details

How to Create Secondary Menu in Squarespace