Turning static design components into client-editable Elementor blocks usually requires writing repetitive PHP class boilerplate by hand. The CodeToWP Custom Elementor Widget Generator lets WordPress developers, Elementor engineers, agencies, and freelancers convert HTML sections into a clean, object-oriented PHP class extending ElementorWidget_Base—complete with Content controls, Style typography/color controls, and WordPress output escaping.
Who the Custom Elementor Widget Generator Is Built For
Installing third-party Elementor widget packs for one or two custom brand blocks introduces dozens of extra scripts and stylesheets into every page load. Yet writing custom widgets from memory means rebuilding namespaces, get_name(), get_categories(), Controls_Manager definitions, typography group controls, and escaping helpers each time.
This Custom Elementor Widget Generator gives you an instant, standards-aligned Widget_Base scaffold pre-configured with Content and Style tabs, ready to drop into /inc/widgets/ or a companion plugin. Using the Custom Elementor Widget Generator cuts bespoke block setup to seconds.
Features, Settings & Supported Outputs
- Widget Metadata Configuration: Configure Widget Title, lowercase Widget ID Slug (automatically converted into
CodeToWP_Widget_{PascalCaseSlug}and filenameclass-widget-{slug}.php), Elementor Category (general,basic, orcodetowp-elements), and icon class (e.g.,eicon-banneror Dashicons). - HTML Presets & Pattern Switching: Choose from 3 presets (Single Feature Box, Service Card Repeater, Pricing Tier) or upload/paste
.html/.txtmarkup. Includingitem_title/item_desc/item_linktokens or multiplecard/item/col/boxclasses switches the scaffold to a Repeater widget. - Generated Elementor 3.5+ PHP Class: Outputs
get_name(),get_title(),get_icon(),get_categories(),get_keywords(),register_controls()(TAB_CONTENT+TAB_STYLEwith Typography, Color, and Box Padding controls), and escapedrender()markup usingesc_html(),esc_url(), andwp_kses_post(). - Code & HTML Render Preview: Switch between the Widget PHP Class editor and HTML Render Preview tab (which previews sample values for built-in tokens), then copy or download
class-widget-{slug}.php.
Practical Example: Scaffolding a Custom Feature Box Class
Sample Widget Inputs
Widget Title: Custom Feature Box
Widget ID Slug: custom_feature_box
Category: codetowp-elements
Icon Class: eicon-banner
Expected Generated ElementorWidget_Base Excerpt
class CodeToWP_Widget_Custom_Feature_Box extends ElementorWidget_Base {
public function get_name() { return 'custom_feature_box'; }
public function get_title() { return esc_html__( 'Custom Feature Box', 'codetowp' ); }
public function get_icon() { return 'eicon-banner'; }
public function get_categories() { return [ 'codetowp-elements' ]; }
protected function register_controls() {
$this->start_controls_section( 'section_content', [
'label' => esc_html__( 'Content', 'codetowp' ),
'tab' => ElementorControls_Manager::TAB_CONTENT,
] );
$this->add_control( 'title', [
'label' => esc_html__( 'Title', 'codetowp' ),
'type' => ElementorControls_Manager::TEXT,
'default' => esc_html__( 'Modern Custom Widget', 'codetowp' ),
] );
$this->end_controls_section();
}
}
Result Explanation: Setting the slug to custom_feature_box produces a uniquely named class CodeToWP_Widget_Custom_Feature_Box implementing Elementor’s registration contract, ready to register inside the elementor/widgets/register hook.
Practical Use Cases
- Elementor & WordPress Developers: Generate clean starting class files for custom CTA banners, icon boxes, or repeatable service grids.
- Frontend Developers: Prepare structured control schemas before pasting bespoke HTML/CSS markup into a widget’s
render()method. - Agencies: Replace bloated third-party widget suites with purpose-built internal client widgets that load zero extra frontend JS.
- Freelancers: Ship editable custom Elementor blocks inside a lightweight client site plugin without locking content to specific themes.
Limitations & Compatibility
- Template Scaffolding vs. Custom HTML Compilation: The PHP generator inspects your HTML solely to decide between its single-box scaffold (
title,description,button_text,button_url) and its repeater scaffold (items_listwithitem_title,item_desc,item_link). Arbitrary HTML markup and custom tokens like{{plan_name}}or{{price}}shown in the HTML Render Preview are not compiled dynamically intorender()—replace the inner HTML ofrender()and add custom controls after downloading. - Sensitive Repeater Substring Trigger: Any HTML containing two or more
class="..."attributes whose names includecard,item,col, orboxtriggers the Repeater output automatically (even on a single feature box if child elements usebox-icon/box-title). - Input & Category Prerequisites: Keep Widget ID Slugs strictly lowercase alphanumeric with underscores (no leading digits or single quotes in Widget Title). If you choose
codetowp-elements, register that custom category viaelementor/elements/categories_registeredfirst or choosebasic/general. - Elementor Compatibility: Uses modern
ElementorWidget_Basemethods compatible with Elementor 3.5+ on PHP 8.0+ and WordPress 6.0+.
Next Steps & Related CodeToWP Tools
Before placing inline icons inside your widget’s render() method, sanitize them with the Sanitized SVG Icon Cleaner, generate custom post types for queryable widgets with the CPT & Taxonomy Code Generator, or read our full tutorial on Wrapping HTML & CSS into a Custom Elementor Widget.