8

I would like to create a global Elementor widget to be called as part of a for each loop. The fields need to be changed based on the arguments I pass to it.

What I am trying to do is call the Elementor global widget from PHP (a plugin), then pass it variables to fill in fields such as title, description, image locations, etc.

I know how to pass variables, I just can't find anywhere how to call a global Elementor widget and how to manipulate the fields directly in PHP.

I did find a close example on another Stackoverflow question that looked like the below, but it doesn't specifically call the global widget.

The below example would work if the global widget can be called and allow me to send the values to the fields as shown below.

function loadheader() {
    $heading_widget = \Elementor\Plugin::instance()->elements_manager->create_element_instance(
        [
            'elType' => 'widget',
            'widgetType' => 'call-to-action',
            'id' => 'stubID',
            'settings' => [
                'title' => 'custom Heading from code',
                'description' => 'custom description',
                'button' => 'success!',
                'image' => 'study-footer.jpg',
                'skin' => 'classic',
            ],
        ],
        []
    );
    $heading_widget->print_element();
}

1 Answers1

2

Maybe too late... ? I tried to make some similar thing : i wanted to create an Widget which can be called from a shortcode to embed it into another widget (like tabs or any WYSIWYG control). I tried to use the_widget() function but it seems that is it only for WP Base widgets, i searched a lot and no found any answer to make it. I think is a namespace issue...(scope of class and functions)

Finally i success... inverting the call : the shotcode make the render, and my control render function call my shortcode with the do_shortcode() function (with params rewritten to match with the shortcode syntax).

I'm not sure that it answer to yout need but perharps...

Jibap
  • 21
  • 5