wp_enqueue_scripts无法添加自定义样式表

时间:2017-01-29 14:37:48

标签: php wordpress

$custom_style = 'css/pre/custom-styles.css';
function custom_stylesheet() {
    wp_enqueue_style( 'aps-custom-style', APS_URL .$custom_style, APS_VER );
}
add_action( 'wp_enqueue_scripts', 'custom_stylesheet' );

APS_URL是目录的网址。

2 个答案:

答案 0 :(得分:1)

您必须将其传递给函数:

$custom_style = 'css/pre/custom-styles.css';
function custom_stylesheet($custom_style) {
    wp_enqueue_style( 'aps-custom-style', APS_URL .$custom_style, APS_VER );
}
add_action( 'wp_enqueue_scripts', 'custom_stylesheet' );

或声明global

$custom_style = 'css/pre/custom-styles.css';
function custom_stylesheet() {
    global $custom_style;
    wp_enqueue_style( 'aps-custom-style', APS_URL .$custom_style, APS_VER );
}
add_action( 'wp_enqueue_scripts', 'custom_stylesheet' );

答案 1 :(得分:1)

wp_enqueue_style( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, string $media = 'all' )

https://developer.wordpress.org/reference/functions/wp_enqueue_style/

在$ vers参数之前,你应首先将数组作为$ deps参数传递。