为什么我的css文件没有在unctions.php中注册?

时间:2018-08-19 作者:Tahridabbas

我想将样式表排入functions.php, 但它没有加载。我的代码有什么问题?

function my_theme_sty() {
    wp_enqueue_style( \'bootstrap\', get_template_directory_uri().\'/assets/css/bootstrap.css\');
}
add_action( \'admin_enqueue_s\', \'my_theme_sty\' );

2 个回复
最合适的回答,由SO网友:Clinton 整理而成

您的功能应该是:

function my_theme_sty() {
    wp_enqueue_style( \'bootstrap\', get_template_directory_uri().\'/assets/css/bootstrap.css\');
}
add_action( \'wp_enqueue_scripts\', \'my_theme_sty\' );

SO网友:Scott

有两个有用的action hooks 用于注册/排队外部脚本(&N);WordPress中的样式:

1。wp_enqueue_scripts:

wp_enqueue_scripts 是将脚本排队时要使用的正确操作挂钩&;前端样式。

因此,如果您想在站点前端添加CSS文件,那么您的代码如下:

function my_theme_sty() {
    wp_enqueue_style( \'bootstrap\', get_template_directory_uri() . \'/assets/css/bootstrap.css\' );
}
add_action( \'wp_enqueue_scripts\', \'my_theme_sty\' );

2。admin_enqueue_scripts:

另一方面,admin_enqueue_scripts 是将脚本排队时要使用的正确操作挂钩&;管理面板的样式。

因此,如果您想在站点的管理面板上添加CSS文件,那么您的代码如下:

function my_theme_sty() {
    wp_enqueue_style( \'bootstrap\', get_template_directory_uri() . \'/assets/css/bootstrap.css\' );
}
add_action( \'admin_enqueue_scripts\', \'my_theme_sty\' );

结束

相关推荐