79423839

Date: 2025-02-08 20:06:42
Score: 0.5
Natty:
Report link

For anyone who stumbles upon this thread:

I found this answer buried somewhere in an Elementor GitHub issue. May it help someone else too:

Original Question by rahulv3a:

Is it possible to call an Elementor widget programmatically with custom arguments like we can call WordPress widgets using the_widget( $widget_class_name, $instance, $args );?

Original Answer by bainternet:

Yes its possible, simply create an instance of the widget class and use print_element method. eg:

$heading_widget = \Elementor\Plugin::instance()->elements_manager->create_element_instance(
    [
        'elType' => 'widget',
        'widgetType' => 'heading',
        'id' => 'stubID',
        'settings' => [
            'title' => 'custom Heading from code',
        ],
    ],
    []
);
$heading_widget->print_element();

I am not 100% sure this solution is viable in the case described above, but I feel it is definitely a good starting point a for different approach.

Reasons:
  • Blacklisted phrase (1): Is it possible to
  • Whitelisted phrase (-1): solution is
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Sturmfink