我需要将第二个脚本中的参数传递给wp\\u enqueue\\u脚本中的第一个脚本
/*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\' );
SO网友:Jeanne Kidaw
您可以将脚本(和样式)排入短代码中,如下所示:
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;
});