无法使用我自己的JS文件来使用Wordpress(4.9)。

时间:2017-11-16 21:09:12

标签: wordpress

我有点腌,哈哈。

这是我的功能:

  function start_group_escapes_4_less() {

    wp_enqueue_style( 'style', get_stylesheet_uri() . '/style.css');
    wp_enqueue_script( 'ge4l', get_stylesheet_uri() . '/js/ge4l.js', array('jquery'), null, true);

  }

  add_action( 'wp_enqueue_scripts', 'start_group_escapes_4_less' );

我检查的每个地方,语法都是正确的。或者是吗? 帮助:(

3 个答案:

答案 0 :(得分:2)

函数get_stylesheet_uri()返回主题style.css文件的URL。

您需要使用get_stylesheet_directory_uri()

function start_group_escapes_4_less() {
    wp_enqueue_style( 'style', get_stylesheet_directory_uri() . '/style.css');
    wp_enqueue_script( 'ge4l', get_stylesheet_directory_uri() . '/js/ge4l.js', array('jquery'), null, true);
}
add_action( 'wp_enqueue_scripts', 'start_group_escapes_4_less' );

答案 1 :(得分:0)

确保文件style.cssge4l.js的目录正确且适用于wp-admin文件。或者尝试在代码中显示的目录中添加符号。

答案 2 :(得分:0)

检查return =&gt;的值<?php echo get_stylesheet_uri(); ?>

使用get_template_directory()?!