我一直在尝试根据条件添加自定义css文件。这就是我想注册那个css文件的原因。但是致命的错误说
致命错误:在第899行的/home/learnenglish/public_html/wp-content/themes/learn/functions.php中调用未定义的函数register_custom_styles()
以下是以下代码:
if ( is_user_logged_in() ) {
if (!register_custom_styles()) {
add_action( 'wp_enqueue_scripts', 'register_custom_styles' );
function register_plugin_styles() {
wp_register_style( 'custom', get_stylesheet_directory_uri( '/custom.css' ) );
wp_enqueue_style( 'custom' );
}
}
}
答案 0 :(得分:0)
试试这个
if ( is_user_logged_in() ) {
add_action( 'wp_enqueue_scripts', 'register_custom_styles' );
}
function register_custom_styles() {
wp_register_style( 'custom', get_stylesheet_directory_uri('/custom.css' ) );
wp_enqueue_style( 'custom' );
}
答案 1 :(得分:0)
问题是,您调用的函数未定义,您定义的函数是否具有其他函数名称
if ( is_user_logged_in() ) {
if (!register_custom_styles()) {
add_action( 'wp_enqueue_scripts', 'register_custom_styles' );
function register_custom_styles() { // change here to register_custom_styles
wp_register_style( 'custom', get_stylesheet_directory_uri( '/custom.css' ) );
wp_enqueue_style( 'custom' );
}
}
}
更改功能名称,它将起作用
答案 2 :(得分:0)
请尝试此功能。您正在调用的函数register_custom_styles未定义,您定义的函数是另一个函数名称。
if ( is_user_logged_in() ) {
if (!register_plugin_styles()) {
add_action( 'wp_enqueue_scripts', 'register_plugin_styles' );
function register_plugin_styles() {
wp_register_style( 'custom', get_stylesheet_directory_uri( '/custom.css' ) );
wp_enqueue_style( 'custom' );
}
}
}