Advertisement
  1. Code
  2. WordPress
Code

Constructing Your WordPress Widget

by
Difficulty:IntermediateLength:ShortLanguages:
This post is part of a series called Introduction to Creating Your First WordPress Widget.
Coding and Registering Your WordPress Widget
Building the Form for Your WordPress Widget

If you've been following this series, you will now have the beginnings of a plugin for your widget. You'll have created the class to code your widget and added the function to register it.

In this tutorial I'll show you how to create the constructor function, which is one of the functions inside your class.

You can find the rest of this series in five parts:

What You'll Need

To follow this tutorial, you'll need:

Creating Your Constructor Function

In this tutorial you'll populate the __construct() function which you created inside your Tutsplus_List_Pages_Widget class.

Open your plugin file and find the constructor function. Edit it so it reads as follows:

This defines the parameters to create your widget. They are:

  • the unique ID of the widget
  • the name of the widget as seen on the Widgets screen
  • an array of options including the description, which is displayed on the Widgets screen. This needs to explain to users what the widget will do.

Now save your plugin file.

You'll now find that if you activate the plugin and look at the Widgets screen, your widget will be displayed. It won't work yet as you haven't created the form or any output for it, but it is there:


Summary

You've now created the constructor function for your widget, which takes you a step closer to having a working widget. In the next tutorial I'll show you how to create the form for your widget which will be displayed on the Widgets screen.

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.