How to Add a WordPress Widget to Your Website

Jul 23 2019

Widgets allow you to easily add content blocks to a designated area in your WordPress theme. These designated areas are called sidebars or widget-ready areas.

A widget ready area in website any area content can be used to display ads, recent articles, or anything you want.

Step 1. Creating a Header Widget Area
First, we need to create a custom widget area. This step will allow you to see your custom widget area on Appearance » Widgets page in your WordPress dashboard.

You will need to add this code to your theme’s functions.php file.

function cl_widgets_init() {
    register_sidebar( array(
        'name'          => 'Custom Widget Area',
        'id'            => 'cl-custom-widget',
        'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'cl_widgets_init' );

This code registers a new sidebar or a widget ready area for your theme.

You can now go to Appearance » Widgets page, and you will see a new widget area labeled ‘Custom Header Widget Area’.

Step 2: Display Your Custom Widget Area in your Website
If you visit your website now, you will not be able to see the text widget you just added to your newly created custom widget.

That’s because we haven’t yet told WordPress where to display this widget area.

Let’s do that in this step.

You will need to edit any theme file. you want to show widget in your website area. Now I’m show this widget in footer. so I’m editing the footer.php file in your theme and add this code where you want to display your custom widget area.


Don’t forget to save your changes.

You can now visit your website and you will see your header widget area.

Thanks for Reading…