我想向shortcode attributes数组添加额外的数据,并使用wp\\u localize\\u脚本将数组传递给js,添加数据并发送数组,但它也打印为:
<script>var custom = {"status":"new","type":"depend","url":"https:\\/\\/www.exemple.com"};</script>
函数中的我的代码。php:
function resources() {
wp_register_script(\'custom_js\', get_stylesheet_directory_uri().\'/assets/js/custom.js\', array(\'jquery\'), \'\', TRUE);
wp_register_style( \'custom_css\', get_stylesheet_directory_uri() . \'/assets/css/custom.css\', array(), \'1\', \'all\' );
}
add_action( \'init\', \'resources\' );
function new_shortcode($atts){
if (!empty($atts)) {
$atts[\'url\'] = MAIN_URL;
wp_localize_script(\'custom_js\', \'custom\', $atts);
}
wp_enqueue_script("custom_js");
wp_enqueue_style("custom_css");
}
add_shortcode(\'custom\', \'new_shortcode\');
是否有其他方法可以做到这一点,而无需在脚本标记中打印数据?