Creating a Custom WordPress Widgets

Prem Tiwari - - WordPress


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!


Prem Tiwari

Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer and a blogger by hobby.

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.