Creating a Custom WordPress Widgets

By Prem Tiwari in WordPress. Updated on


WordPress widgets provides a simple way of giving any information of your website users. It can be easily dragged and dropped in your widget area. Navigate to the Appearance » Widgets section in your WordPress dashboard to get the list of available widgets. Creating a WordPress widgets is just like creating a WordPress plugin. It’s easier to code than a plugin which can have more than one file. Below are the major functions to create your own widgets.

The WP_Widget class is located in wp-includes/widgets.php

Register your own widget using the widgets_init hook:

Update WordPress Widgets Data

You can update your widget data by using admin panel. Use bellow code snippets :

Display WordPress Widgets on Frontend

After update your data from admin section, use bellow code snippets to display the output :

Complete Example for the widget

Open functions.php file from your current activated theme and copy bellow code and paste it to the end of code. Now go to Appearance » Widgets section in your WordPress dashboard and you will see your widget available there.

 
It’s easier to copy and paste. Have fun!

Sharing is caring!


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

You might also like:

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.