0

I need to pass the parameters present in the second script to the first script in the wp_enqueue_script

/*FIRST SCRIPT*/
function add_script() {
    wp_enqueue_script('kross-js', 'https://'EDITOR-ID'kross1.com/widget/6.js?lang=it&be_id='USER-ID', array(), '' , false);
}

add_action( 'wp_enqueue_scripts', 'add_script' );

/*SECOND SCRIPT*/

function kross_shortcode( $atts ) {

    // Attributes
    $atts = shortcode_atts(
        array(
            'USER-ID' => '',
            'EDITOR-ID' => '',
        ),
        $atts
    );

return '<div id="kross-widget">  </div> ';

}

add_shortcode( 'kross', 'kross_shortcode' );
1

you can enqueue scripts (and styles) in the shortcode like that :

add_shortcode("kross", function ($atts, $content, $tag) {


    $atts = shortcode_atts([
        'user-id' => '',
        'editor-id' => '',
    ], $atts);



    wp_enqueue_script(
          "kross-js"
        , "https://{$atts["editor-id"]}kross1.com/widget/6.js?lang=it&be_id={$atts["user-id"]}"
    );


    $result = "kross result";

    return $result;

});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.