我已经注册了应该加载到head部分的脚本。但出于某种原因,我没有把这些链接加载到head中。这些脚本不是在页眉中加载,而是在页脚中加载。
add_action(\'init\', \'my_enqueued_assets\');
function my_enqueued_assets() {
//Register Css
wp_register_style(\'my-css\', MY_PLUGIN_URL.\'css/my_styles.css\');
wp_register_style(\'my-admin-css\', MY_PLUGIN_URL.\'css/my_admin_styles.css\');
//Register JS
wp_register_script(\'my-jquery-min\', MY_PLUGIN_URL.\'js/jquery-3.2.1.min.js\');
wp_register_script(\'my-script-min\', MY_PLUGIN_URL.\'js/my_isotope.min.js\');
wp_register_script(\'my-script\', MY_PLUGIN_URL.\'js/my_isotope.js\', array(\'jquery\'), my_PLUGIN_VERSION, false );
wp_register_script(\'my-lightbox-script\', MY_PLUGIN_URL.\'js/my-lightbox.js\', array(\'jquery\'), my_PLUGIN_VERSION, false );
wp_register_script(\'my-prefix-script\',MY_PLUGIN_URL.\'/js/myscript.js\', array(\'jquery\'), \'0.1\',false );
}
我将这些脚本加载到shortcode中,以便在只使用或调用shortcode时加载脚本和样式。
function my_shortcodes_init()
{
function my_shortcode($atts = [], $content = null)
{
//default portfolio value
$id = 1;
wp_enqueue_style(\'my-css\');
wp_enqueue_script(\'my-jquery-min\');
wp_enqueue_script(\'my-script-min\');
wp_enqueue_script(\'my-script\');
wp_enqueue_script(\'my-lightbox-script\');
if (isset($atts["id"])) {
$id = $atts["id"];
}
require MY_PLUGIN_DIR.\'views/isotope.php\';
}
add_shortcode(\'MY_GALLERY\', \'my_shortcode\');
}
add_action(\'init\', \'my_shortcodes_init\');