Contents
Intro
In this two part tutorial, I’ll guide you through the process of creating a custom Elementor Widget. In some case scenarios, say a custom website with unique functionalities, an out-of-the-box solution may be nowhere to be found. One may decide to use shortcodes instead; this, however, may not satisfy your client’s needs and is both less elegant and less configurable.
Our Widget will create a custom posts loop with several settings. In this part, we’ll set up bare-bones for our Widget, that is:
- Some simple settings: A title displayed above the posts, a number of posts to choose from
- A custom Widget Icon
- Widget keywords used to filter the Widget in the Elementor Sidebar
Elementor Custom Widget Visuals
After the tutorial, your Widget will render several defined posts one after another and have the following icon display:
The widget settings panel will look as follows:
Finally, the widget will display posts in the following way:
Elementor Custom Widget Code
The following snippet of code can be placed in two places:
- In a Custom Plugin
- Within Child Theme’s functions.php file
The tutorial will cover the second case scenario, where we will place the widget’s code within a subdirectory of our theme. Place that one in a file called widget-custom-blog-loop.php under the elementor-widgets directory. Note: For clarity reasons, I commented the code directly within the following two snippet files.
Now, within your theme’s functions.php file, place the following snippet of code. It will load our New Widget’s code from the aforementioned directory.
With the above code in place, our results should be nearly identical to the images I have posted above (depending on the theme you use, the output could look different, as we haven’t styled our Widget yet, so it’s using the default theme styles).
Let me know in the comments below if you need any help or extra explanation regarding this part of the tutorial. I’ll be more than happy to offer my support here.
In part two of this guide, we’ll cover extra options to play with:
- Styling our Widget
- Additional Back End Controls
- Loading external CSS and .JS files
Resources
- https://wp-doin.com/elementor-custom-widget-tutorial-part-2/ — Part 2
- https://elementor.github.io/elementor-icons/ – Elementor Icons to choose from, used the get_icon method
- https://developers.elementor.com/docs/widgets/widget-data/ – Base information of the Widget structure
- https://developers.elementor.com/docs/controls/ – Elementor Controls documentation