Wordpress 根本不加载插件脚本

Wordpress not loading scripts for plugin at all

所以我有在我的插件中加载我的脚本的操作。

add_action( 'init', array( $this, 'loadAssets' ) );

对应的函数设置为:

public function loadAssets() {
        // add stylesheet to all pages
        wp_enqueue_style(
                'styles', // handle
                plugins_url( 'styles/main.css', __FILE__ ), // src for js                
                array(),
                WP_DEBUG ? time() : $this->version // version, null removes version, false uses wordpress version
                );

        wp_register_script( 'jquery.ezmark.min', // handle
                plugins_url( 'js/jquery.ezmark.min.js', __FILE__ ), // src for js
                array( 'jquery' ), // dependancies
                WP_DEBUG ? null : $this->version, // version, null removes version, false uses wordpress version
                true
                );
}

现在 main.css 加载完全正常,但无论我做什么,Javascript 文件根本无法加载。

他们昨天工作得很好,现在当我加载网站时他们停止工作。

如有任何帮助,我们将不胜感激。

改变这个,

add_action( 'init', array( $this, 'loadAssets' ) );

对此,

add_action( 'wp_enqueue_scripts', array( $this, 'loadAssets' ) );

要在您的插件中包含 CSS 和 jQuery 很容易,试试这个:

// register jquery and style on initialization
add_action('init', 'register_script');
function register_script() {
    wp_register_script( 'custom_jquery', plugins_url('/js/custom-jquery.js', __FILE__), array('jquery'), '2.5.1' );

    wp_register_style( 'new_style', plugins_url('/css/new-style.css', __FILE__), false, '1.0.0', 'all');
}

// use the registered jquery and style above
add_action('wp_enqueue_scripts', 'enqueue_style');

function enqueue_style(){
   wp_enqueue_script('custom_jquery');
   wp_enqueue_style( 'new_style' );
}