admin管理员组文章数量:1429061
Im trying to modify WP admin area. I put this in the functions.php but the styling only takes effect the first time it runs the stylesheet, if I do any changes afterwards it doesnt update. For now it only works if I rename the stylesheet.
function custom_admin() {
$url = get_settings('siteurl');
$url = $url . '/wp-content/themes/astra-child/wp-admin.css';
echo '<link rel="stylesheet" type="text/css" href="' . $url . '" />'; }
add_action('admin_head', 'custom_admin');
Im trying to modify WP admin area. I put this in the functions.php but the styling only takes effect the first time it runs the stylesheet, if I do any changes afterwards it doesnt update. For now it only works if I rename the stylesheet.
function custom_admin() {
$url = get_settings('siteurl');
$url = $url . '/wp-content/themes/astra-child/wp-admin.css';
echo '<link rel="stylesheet" type="text/css" href="' . $url . '" />'; }
add_action('admin_head', 'custom_admin');
Share
Improve this question
asked Jun 8, 2019 at 7:49
bozenbozen
611 silver badge3 bronze badges
1 Answer
Reset to default 1A more standard way to enqueue stylesheets in WP admin is to use wp_enqueue_style
function on admin_enqueue_scripts
hook.
if I do any changes afterwards it doesnt update
This sounds like a browser cache isssue. You can bust the cache by adding a dynamic version number parameter to the stylesheet url with the native php function filemtime
. It returns the unix time when the file was last changed. Like so,
// add to functions.php
function my_prefix_add_admin_styles() {
wp_enqueue_style( 'my_admin_styles', get_stylesheet_directory_uri() . '/wp-admin.css', false, filemtime( get_stylesheet_directory() . '/wp-admin.css' ) );
}
add_action( 'admin_enqueue_scripts', 'my_prefix_add_admin_styles' );
本文标签: menusWP admin style not refreshing
版权声明:本文标题:menus - WP admin style not refreshing 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745425255a2658081.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论