javascript - 脚本加载问题?

标签 javascript php jquery html wordpress

所以我正在将 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');
?>

Default Scripts Included and Registered by WordPress

关于javascript - 脚本加载问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28839123/

相关文章:

javascript - Angular 时间选择器没有收到错误?

javascript - 动态加载图像,错误时中断循环

jquery - 使用 Animate.css 淡出然后淡入

javascript - 在 Javascript 中可以删除特权吗?

javascript - 在 Javascript 中获取表格

javascript - Jquery密码(4位数字)验证

javascript - 为什么 IE8 在 jquery window.resize 事件上挂起?

php - 我想在下拉列表中添加表结构

php - 创建 HTML 文件的 Javascript 中存储的数据的 PDF

php - 自定义表单日期和时间选择中的 Joomla 2.5 日历字段类型