What Are WordPress Widgets?
WordPress widgets make it simple for you to add extra functions to your website through a very simple drag-and-drop interface.
- As shown in the below image, WordPress includes a few basic widgets by default.
Also, WordPress allows you to create your own custom widgets with an advanced level of access that doesn’t come with default widgets. To create a custom widget for your WordPress dashboard, follow these simple steps
Creating Custom Widget
In WordPress, You can create a custom widget using the WP Widget class. In that, we will use minimum 4 functions to create a custom widget.
1. __construct(): This function provides the basic widget information.
2. widget(): This function contains the widget output.
3. form(): This function defines the widget settings displayed in the WordPress dashboard.
4. update(): This function updates the widget settings in the database.
You can create a custom widget by adding the following code to the functions.php file.
In the above code, we have defined a new function called new_custom_widget(). It registers our widget using the widget ID, which is specified in the __construct() function.
Next, we have tied this function to widgets_init, which loads the widget by using WordPress’s add_action() method.
Now you can use the newly-installed widget.
- Go to the Appearance menu, and select Widgets. You should see a widget named Custom Widget in the Available Widgets list.
- Next, drag the widget and drop it in the Footer section on the right side of the page as shown below.
Here are more blogs on WordPress
- Custom Logo WP Login Page
- How to change WordPress login URL without plugin
- How to create a wordpress custom widget?
Looking for a top IT consulting services provider specializing in salesforce consulting, mobile app development, and web application development? Choose Erudite Works. We offer cutting-edge technology and engineering solutions for businesses, trusted by millions of users daily. Contact Us.
0 Comments