0

I have function that convert widget options to shortcodes args.

abstract class MOD_Widget extends WP_Widget {

    [...]
    [...]

    public function params_to_shortcode( $params ) {
        $sc_attrs = array();
        foreach ($params as $key => $attr) {
            if (is_array($attr)) {
                $attr = implode(',', $attr);
            }

            $sc_attrs[] = "{$key}=\"" . esc_attr($attr) . '"';
        }

        return $sc_attrs;
    }

}

Widget:

class MOD_Widget_Base extends MOD_Widget {

    [...]
    [...]

    public function widget( $args, $instance ) {

        $widget_tag = str_replace( '-', '_', $this->widget_id );
        $shortcode = do_shortcode(
            '[' . $widget_tag . ' ' . implode( ' ', $this->params_to_shortcode( $instance ) ) . '/]'
        );

        echo $args['before_widget'];

        echo '<pre>';
        echo $shortcode;
        echo '</pre>';

        echo $shortcode;

        echo $args['after_widget'];
    }

}

When I add my widget into sidebar then this work fine. Output: [mod_widget_base base_title="" posts="10" thumbnail="0"/] When I use my widget in Elementor page builder then I have only shortcode tag without args: [mod_widget_base /]

How to use this solution in the Elementor page builder ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.