向wp-admin添加自定义样式表

时间:2013-08-20 作者:user1933824

我在WP-ADMIN区域无法获得自定义样式表。plugins_url(\'style.css\', __FILE__) ); 我必须在名为css的插件中创建文件夹,还是只复制.csswp-admin/css 目录

我两个都试过了,似乎对我不起作用。

以及应将哪些值替换为__FILE__?

对不起,我对这些东西有点陌生。

/*ADDS STYLESHEET ON WP-ADMIN*/
add_action( \'admin_enqueue_scripts\', \'safely_add_stylesheet_to_admin\' );
    function safely_add_stylesheet_to_admin() {
        wp_enqueue_style( \'prefix-style\', plugins_url(\'style.css\', __FILE__) );
    }


/*ADDS MY CUSTOM NAVIGATION BAR ON WP-ADMIN*/
add_action(\'admin_head\', \'custom_nav\');
function custom_nav(){
    include(\'custom_nav.html\');

}

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

According to WordPress Codex (here):

admin_enqueue_scripts is the first action hooked into the admin scripts actions.

Example

Loading a CSS or JS files for all admin area:

//from functions.php

//First solution : one file
//If you\'re using a child theme you could use:
// get_stylesheet_directory_uri() instead of get_template_directory_uri()
add_action( \'admin_enqueue_scripts\', \'load_admin_style\' );
function load_admin_style() {
    wp_register_style( \'admin_css\', get_template_directory_uri() . \'/admin-style.css\', false, \'1.0.0\' );
    //OR
    wp_enqueue_style( \'admin_css\', get_template_directory_uri() . \'/admin-style.css\', false, \'1.0.0\' );
}

//Second solution : two or more files.
//If you\'re using a child theme you could use:
// get_stylesheet_directory_uri() instead of get_template_directory_uri()
add_action( \'admin_enqueue_scripts\', \'load_admin_styles\' );
function load_admin_styles() {
    wp_enqueue_style( \'admin_css_foo\', get_template_directory_uri() . \'/admin-style-foo.css\', false, \'1.0.0\' );
    wp_enqueue_style( \'admin_css_bar\', get_template_directory_uri() . \'/admin-style-bar.css\', false, \'1.0.0\' );
}

do i have to create folder in my plugins named css or do i just copy my .css to the wp-admin/css directory?

No, put your CSS file together with the other, in your theme directory, then specify the path with:

get_template_directory_uri() . \'/PATH_TO_YOUR_FILE\'

For ex my file name is admin-style.css and i put it in a folder named css my path will looks like:

get_template_directory_uri() . \'/css/admin-style.css\'

Hope it helps!

SO网友:Mohammed Muzammil

如果要对管理面板进行CSS更改。在函数中粘贴以下代码。子主题的php

add_action(\'admin_head\', \'my_custom_fonts\'); // admin_head is a hook my_custom_fonts is a function we are adding it to the hook

function my_custom_fonts() {
  echo \'<style>
    #posts-filter table.posts{
        table-layout:auto;   
    }
  </style>\';
}

SO网友:tagformat.com

对于那些希望在自定义插件(或插件文件夹)的管理区域中添加CSS文件的用户:

if (is_admin()) {
获取src if文件夹中的文件:(…myPluginFolder/myfolder/css/my.css)

$myCssFileSrc = plugins_url( \'/myfolder/css/my.css\', __FILE__ );
获取根插件文件夹中的src if文件:(…myPluginFolder/my.css)

$myCssFileSrc = plugins_url( \'my.css\', __FILE__ );
排队(激活)样式表文件:

wp_enqueue_style( \'my-css\', $myCssFileSrc );
} //endif;
主插件文件(myplugin.php)中的所有操作

结束

相关推荐

WordPress子域wp-admin重定向到主域

我们在地址www.example上安装了wordpress。com。我们希望有一个作为子域的开发站点,所以我们创建了一个子域dev.example。cpanel上的com。创建了其数据库的副本,并将文件复制到dev.example的根目录中。com。然后修改wp配置。php指向重复的db。现在的问题是,当我们尝试访问dev.example时。com/wp管理员,它重定向到https://www.example.com/wp-login.php?redirect_to=https%3A%2F%2Fdev.e