的两大部件得到一个脚本加载:
<?php wp_register_script('script-handle', 'script-location'); ?>
和
<?php wp_enqueue_script('script-handle'); ?>
wp_enqueue_script不会加载脚本,除非它已先行注册(注意,WP附带了许多预注册脚本,如jQuery的,所以在这种情况下,所有你需要做的是排队剧本。但是,对于未绑定在WP中的自定义脚本,您需要先注册它)。
因此,基于这个问题,假设你已经将脚本放在你的THEME目录下的文件夹“includes”中(例如wp-content/themes/my-theme/includes/links.js ),那么这就是你会在你的主题的functions.php文件做什么:
<?php
function my_theme_register_scripts() {
wp_register_script('my-script-handle', get_bloginfo("template_url") . '/includes/links.js');
wp_enqueue_script('my-script-handle');
}
// If you want to use the script on the FRONT end of the site, then....
add_action('init', 'my_theme_register_scripts');
// If you want to use the script on the BACK end of the site....
add_action('admin_init', 'my_theme_register_scripts');
?>
而且大卫 - 是正确的 - 你需要确保你的主题既有wp_head()和wp_footer()调用在其中,否则的东西不会按预期的那样工作...
给我们看一些代码... – 2012-02-02 16:51:53