How to add custom widget to WordPress

Adding widgets to your wordpress site is very simple and super easy. Which means that you can now customize the display of widgets on your wordpress site. WordPress widgets enable users to simply drag and drop elements into their site, and in this simple tutorial i will show you how to simply add custom widgets

First, add this codes to functions.php

if (function_exists('register_sidebar')) {
'name' => 'Custom Widgets',
'id' => 'custom-widgets',
'description' => 'The Custom widgets for your website.',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'

Second, add the codes below to which the area you want the widget to display (eg. header.php)

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

And that’s it, just navigate to your wordpress admin Appearance>>Widgets and you can see the Custom Widgets title on the dashboard.

Scroll To Top