所以我正在将 html 模板转换为 WordPress 主题,我已经在 index.php、footer.php、header.php 和 style.css 中添加了所有特定标签,看起来我的脚本不会正确加载。 这是我要转换的网站:http://iulian.cablevision.ro/rock4life/ 我已经在本地主机上安装了 wordpress 以在沙箱中运行。我认为问题出在functions.php 上?这就是我的网站加载方式:http://iulian.cablevision.ro/rock4life_wp/ 。我还在开始时删除了加载屏幕,因为根本不会加载网站...检查whit firebug 将不会显示任何脚本。 function.php 文件:
<?php
function firstwp_resources(){
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts','firstwp_resources');
function your_scripts() {
wp_register_script('jquery', 'js/jquery.js', true);
// This registers your script with a name so you can call it to enqueue it
wp_enqueue_script( 'jquery' );
// enqueuing your script ensures it will be inserted in the propoer place in the header section
wp_register_script('jquery.reveal', 'js/jquery.reveal.js', true);
wp_enqueue_script( 'jquery.reveal' );
wp_register_script('jquery.backstretch', 'js/jquery.backstretch.min.js', true);
wp_enqueue_script('jquery.backstretch');
wp_register_script('jquery.tweet', 'js/jquery.tweet.js', true);
wp_enqueue_script('jquery.tweet');
wp_register_script('mediaelement-and-player', 'js/mediaelement-and-player.min.js', true);
wp_enqueue_script('mediaelement-and-player');
wp_register_script('custom', 'js/custom.js', true);
wp_enqueue_script('custom');
wp_register_script('jquery.placeholder', 'js/jquery.placeholder.min.js', true);
wp_enqueue_script('jquery.placeholder');
}
add_action('wp_enqueue_scripts', 'your_scripts');
// This hook executes the enqueuing of your script at the proper moment.
最佳答案
这将确保脚本加载,并确保仪表板的脚本安全。
<?php
function firstwp_resources() {
if (!is_admin()) {
// Default Scripts
wp_deregister_script('jquery');
wp_register_script('jquery', get_template_directory_uri().'/assets/js/jquery.js', false, null);
wp_enqueue_script('jquery');
wp_deregister_script('jquery-mig');
wp_register_script('jquery-mig', get_template_directory_uri().'/assets/js/jquery-mig.js', false, null);
wp_enqueue_script('jquery-mig');
// Other Scripts
wp_enqueue_script('name', get_template_directory_uri().'/assets/js/name.js', false, null, true); // loads in footer
}
}
add_action('wp_enqueue_scripts', 'firstwp_resources');
?>
关于javascript - 脚本加载问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28839123/