Install the Elementor plugin within the WordPress website.
Create a new page within WordPress and name the page Custom Widget.
Click Edit with Elementor from the Custom Widget page.
I created a new installation of WordPress on my local computer and named it LearningWPThemes.
You can name the new WordPress website whatever you want.
If you are going to create the widget on a hosted WordPress server, you will need to access the File Manager area plugin folder.
CREATE THE PLUGIN
Open the plugins folder in the wp-content of the WordPress website.
Create a new folder and name it wpherocoder-elementor-widgets in the plugin folder.
Inside the wpherocoder-elementor-widgets folder create the plugin main file.
Create a new text file and rename it wpherocoder-elementor-widgets.php.
Open the wpherocoder-elementor-widgets.php file in a text editor application.
Open the file to edit in vs code.
Add the plugin declaration inside the wpherocoder-elementor-widgets.php file.
<?php
/**
* Plugin Name: WPHeroCoder Elementor Widgets
* Description: Elementor custom widgets from WPHeroCoder.
* Plugin URI: https://wpherocoder.com/plugins
* Version: 1.0.0
* Author: WPHEROCODER
* Author URI: https//wpherocoder.com/
* Text Domain: wpherocoder-elementor-widget
*
* Elementor tested up to: 3.5.0
* Elementor Pro tested up to: 3.5.0
*/
Click on save and go to the WordPress plugins area and click refresh and you will see the new plugin added.
Click Activate to (ACTIVATE the Plugin) within WordPress.
The WPHeroCoder Elementor Widgets it active.
Go back to the editor and start adding the code to build the plugin functions.
Add the lines of code to your wpherocoder-elementor-widgets.php file.
Here is what we have so far:
Next, we need to create a new widgets folder within our plugins wpherocoder-elementor-widgets folder.
Click inside the new widgets folder and create a new file and name it card-widget.php file.
You will need to create a txt file and then name it card-widget and change the txt extension to php.
New file called: card-widget.php
Open the card-widget.php in the text editor and add the code to build the functionality of the card widget.
Place the code in the card-widget.php file.
We will keep building the functionality of the card widget.
Here is a sample of what we have so far.
The get_title will show the name of the icon widget within Elementor environment toolbox, see the example below.
Open the Custom Widget page and edit with Elementor.
Next, we will change the icon of the widget.
Here is a whole list of icons that you can use in Elementor.
// HELP for your users
If you want to display help from your widget add the following function.
Here is what was changed in the Elementor toolbox.
Next, we are going to create the GET Categories function.
In our example the widget is placed in the general dropdown section.
We could have chosen to put our widget in any of the categories that Elementor offers.
You can find the control under the General tab. (we can place the widget in different categories).
Next, we are going to create the keyword’s function.
When you type out the keywords in the widget search textbox this function will help users find the widget.
Still inside the register_controls we are going to code the add_control function.
We are adding the TEXT control.
Here is what is happening in the Elementor widget.
We created the Card Title and input box.
Next, we are going to code the TEXTAREA control of the widget.
Here is what is happening in the Elementor widget.
Next, we are going to code the Render part of the widget that will be displayed on the front end of the Custom Widget page.
Open the Custom Widget page to view the widget.
The widget displays the title and description.
STYLE:
We are going to create the Style tab in the Elementor menu toolbox for our widget.
Here is what we have so far.
Here is what it will look like in Elementor.
You should see the Style section.
You won’t see any functionality under the style yet.
We will code that next.
Write the code to add the heading for the style.
Here is what it will look like in Elementor.
Next, we are going to write the code of Color control.
We are going to code the widget giving it a default color of Red (#f00).
Here is what we have so far in the code editor.
Here is what it will look like in Elementor – Remember that we have coded default with Red (#f00) but I changed it to green.
Give it a try, change the color of the control and pick any color.
Next, we are going to code the title typography section.
Here is what our widget looks like in Elmenetor.
Now we are going to code the description area of the Elementor widget.
Here is what it will look like in Elementor.
Remember that we have coded default with Red (#f00) but I changed it to blue by changing the color picker.
Next view the Custom Widget page and you can see the output on the front end.
Conclusion
Hopefully now you have a good understanding of how widgets are built in Elementor.
