WordPress

How To Registering A Sidebar And Use In Your Custom Theme In WordPress

Here we learn about how to register a sidebar and use it in your custom theme In WordPress.

Custom code copied and paste into your child theme’s functions.php file.

1. register_sidebar()

It has more parameters see below the code example.

<?php
function myblog_widgets_init() {
  register_sidebar( array(
    'name'          => esc_html__( 'Footer Column 3', 'text-domain' ),
    'id'            => 'myblog-footer-col-3',
    'description'   => esc_html__( 'Add widgets here.', 'text-domain' ),
    'before_widget' => '<section id="%1$s" class="widget %2$s">',
    'after_widget'  => '</section>',
    'before_title'  => '<h2 class="widget-title">',
    'after_title'   => '</h2>',
  ) );
  
}
add_action( 'widgets_init', 'myblog_widgets_init' );
?>

The following list of the code parameters.

  • name – widget sidebar name.
  • id – your theme using dynamic_sidebar function and string must be lowercase.
  • description – The sidebar description. It displays in the admin Widgets panel.
  • class – you can add CSS class name to assign.
  • before_widget – It is placed before every widget HTML.
  • after_widget – IT is placed after every widget HTML.
  • before_title –It is placed before the title of each widget HTML.
  • after_title – It is placed after every title HTML.

2. dynamic_sidebar()

How to display the sidebar using the dynamic_sidebar function.

Add below code in the footer file:

<?php
<div class="footer-bottom">
  <div class="container">
    <div class="footer3-sec">
      <?php 
      if ( is_active_sidebar( 'myblog-footer-col-3' ) ) :
        dynamic_sidebar( 'myblog-footer-col-3' );
      endif;
      ?>
    </div>
  </div>
</div>
?>

OUTPUT:

1) Set widget in the admin

2) footer display

Rahul Prajapat

I’m Rahul Prajapat. I’m a WordPress developer and Author at TheCodeHubs. I have good skill of Html, CSS, JQuery, SQL, Web API, PSD to HTML/PSD to WordPress, WordPress Theme/Plugin Customization, create or modify short code, customize visual composer short code or integrate new short code with visual composer, can create custom metabox for any post type in WordPress admin.

Share
Published by
Rahul Prajapat

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago