Wordpress: create widget - how it works
If you want to create your own widget in WordPress, this takes a few steps. In this practical tip, we will show you which commands you need for this.
Basics: Create your own WordPress widget
For your own widget to work, it needs these five functions.
- First start with "function_construct ()" to initialize the widget.
- Then you continue with the design of the widget, which you define with "function widget ()".
- A design must also be available in the admin area. This is defined with "function form ()".
- To keep the settings current, you need "function update ()".
- Finally, you need "function init ()" to register the widget.
- In the screenshot you can see the rough structure of the PHP file for your plugin. This file must be in the "wp-content / plugins" directory for the widget to be recognized.
Create your own widget in WordPress - so it'll work
- You also need a so-called header so that the plugin is recognized as such.
- The screenshot shows how such a header should look like.
- Enter your individual information in the header and add it to the beginning of the PHP file.
- You will then find the plugin in the WordPress admin area and can activate it there.
- You can find out what a simple "About me" widget can look like on this page.
- Download the PHP file from there and paste it into the "wp-content / plugins" directory. Then activate the widget in the admin area so that it is visible.
If you would like to create your own contact form in Wordpress, we will show you in the next practical tip how you can do this.