0

im having problems loading my custom stylesheet inside wp-admin

here is my code to load stylesheet inside my theme's function.php

add_action('admin_head', 'my_custom_style');

function my_custom_style() 
{
  echo '<link rel="stylesheet" href="' . get_bloginfo('template_url') . '/css/style.css" media="screen" type="text/css />';  
}

and some functions that adds <div> on my admin-header and admin-footer

add_action('admin_head', 'echo_html');
function echo_html(){
    echo '<div class="superwrap"> test superwrap';

}

add_action('wp_footer', 'echo_foo');
function echo_foo(){
    echo '</div>';

}

when i echo below code inside my my_custom_style function, it works. but when i link the stylesheet, it doesnt load.

 <style>
.superwrap {
    padding:20px 10px 10px 5px;
    background:green;
    min-height:100%;
    } 
</style>
3

To include custom styles and scripts, you should be using wp_enqueue_style() like so:

add_action('admin_enqueue_scripts', my_enqueue_admin_styles);
function my_enqueue_admin_styles() {
    wp_enqueue_style('my-admin-style', get_bloginfo('template_url') . '/css/style.css', array(), 'screen');
}

You want to use this method, as it will add your CSS after the default and thus it will allow you to overwrite the WP styles.

Then, look at the source of any admin page, and search for your CSS. Make sure the URL there is accurate. If it is, the style will load.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.