Can’t call external stylesheet for WordPress admin (using wp_admin_css)?

I tried the following:

<?php

function my_wp_admin_css() {
  echo '<link rel="stylesheet" href="/wp-content/plugins/custom-admin-style/wp-admin.css" type="text/css" />';
}

add_action('wp_admin_css','my_wp_admin_css');

but nothing is being displayed in the WordPress admin.

Read More

What I’m doing wrong?

Related posts

Leave a Reply

1 comment

  1. You need to use wp_enqueue_style and hook it into admin_print_styles

    add_action( 'admin_print_styles' , 'my_wp_admin_css' );
    
    function my_wp_admin_css() {
    
          wp_enqueue_style('my_admin_style' , WP_PLUGIN_URL . '/myPlugin/stylesheet.css' );
    }
    

    If you just want the stylesheet on your plugins page you can use:

    $mypage = add_management_page( 'myplugin', 'myplugin', 9, __FILE__, 'myplugin_admin_page' );
    add_action( "admin_print_styles-$mypage", 'myplugin_admin_head' );
     
    function myplugin_admin_head() {
        // what your plugin needs in its <head>
    }