How to create a custom widget in wordpress

At first, you should know that custom widget in word press can help you to add non content elements in your websites. But you don’t know how? Widgets causes you can add advertisement and banners to your websites.

In this article, we tell you about it. After read this article, you can easily create a custom widget in your wordpress websites.

What does word press widget mean?

Word press widget include some codes that can use it on your website. Word press have a set of widgets that you can use one of them that you like.

create a custom widget

beginners or developers can create their custom widgets in word press. You can easily create your custom widgets in word press. When you plugin, you can add some different themes such as photo gallery, contact form and so on to your sidebar.

A way to create a custom widgets in word press

Before you create a custom widgets, you should have word press on your computer, if you don’t have you should install it.

Here are some ways that you should use to add custom widgets code.

One way is that you can build site plugin and paste the code on it. This way is very ideally. Another way that you can paste the code on php file, but you can use this way only the particular theme is active.

The third way that you use code snippets. In this way. you can add your code on word press websites easily. This is the easiest and most convenient way. we recommend this way to beginners.

Our goal is that you familiar with word press widget class. In below, you read about different word press widget class. So stay with us.

Create a basic word press widget

Its good to know that every word press widget have the word press widgets class.

Here are 18 ways in word press that can be used for word press widget class.

Because you have to learn this training process, you focus on methods that describe in below.

create a custom widget

  1. construct: this is the part that we can build the widget id and description.
  2. widget: this is the part that we define the output for widget.
  3. form: with this part we can create the form by option that exists in widget.

Update: in this part we should save the widget option.

In below, we describe the code that use for the word press widget.


























// Creating the widget

class wpb_widget extends WP_Widget {


// The construct part

function __construct() {




// Creating widget front-end

public function widget( $args, $instance ) {




// Creating widget Backend

public function form( $instance ) {




// Updating widget replacing old instances with new

public function update( $new_instance, $old_instance ) {




// Class wpb_widget ends here


 We should say that the final cod exists in where the widget is register and load in word press as custom widget in word press.





function wpb_load_widget() {

register_widget( ‘wpb_widget’ );


add_action( ‘widgets_init’, ‘wpb_load_widget’ );

 If you collect all of the code, you can create the basic widget. You just paste the widget code on plugin or in php file.

After that you paste the code, go to the appearance/ widget. When you see the new widget, drag and drop it in to sidebar. Then you can add your intended text and then click on save button. After that you can see your new create a custom widget in word press that its active.

When you click on save button, every changes about your websites save too.

 Don’t forget that, if you create custom widget in word press, you can easily replace wpb text domain in your theme text.

We hope that this article could be useful for you and you can use it. Stay tunes for our next practical article and follow us on face book or twitter.  Share our article with your friends.

If you like this article and the practical process, like us on youTube.

read more:

0 CommentsClose Comments

Leave a comment

subscribe to newsletter

Get the latest posts and articles in your email

We promise not to send spam 

subscribe to newsletter

Get the latest posts and articles in your email

We promise not to send spam 

subscribe to newsletter

Get the latest posts and articles in your email

We promise not to send spam