How to create custom widget in WordPress ?

How to create custom widget in WordPress ?

Hi guy’s today i am gonna tell you how to create custom widget in WordPress. Widget is a very important part when you are building website in WordPress. Basically WordPress already have some widgets but when we are building the site we needs the more widgets to use in the site so follow these instructions to create widget in WordPress.

Before moving on let me tell you one thing that Please do not create new function for widget it has already present there you just have to add some code within the function and thats it. See the below instructions.

Step 1

Please put these code in your function.php file within this function.

function themename_widget_init()
your widget code goes here ..

Your widget code will be

register_sidebar( array(
    'name' => __( 'Widget Name', 'themename' ),
    'id' => 'widget_id',
    'description' => __( 'widget description.', 'themename' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
) );

and your done now go to WordPress backend go to widget under appearance you can see the new widget name “Widget Name” you can change name whatever you wish to.

Please see this screenshot


Now you can display this widget anywhere by using this function

<?php dynamic_sidebar('widget-id'); ?>

Hope you like this tutorial if you have any question or comments please fill the form below. We would love to help you anytime.
Good Luck !

27 thoughts on “How to create custom widget in WordPress ?

  1. Been sitting eyes wide open behind these four walls, hoping you’d call It’s just a cruel existence like there’s no point hoping at all. Baby, baby, I feel crazy, up all night, all night and every day Give me something, oh, but you say nothing. What is happening to me? I don’t wanna live forever, ’cause I know I’ll be living in vain. And I don’t wanna fit wherever. I just wanna keep calling your name until you come back home.Thank you

  2. I’ve been sleepless at night. ‘Cause I don’t know how I feel. I’ve been waiting on you
    Just to say something real.There’s a light on the road. And I think you know. Morning is coming. And I have to go.I don’t know why, I don’t know why. We need to break so hard. I don’t know why we break so hard But if we’re strong enough
    To let it in. We strong enough. To let it go.

  3. I believe there are many other people who are interested in them just like me! How long does it take to complete this article? I hope you continue to have such quality articles to share with everyone! I believe a lot of people will be surprised to read this article! Thanks for your post!

Leave a Reply