1

How can I add css code to admin_enqueue_scripts? I did this for login_enqueue_scripts its working fine but same thing is not working for admin_enqueue_scripts.

Following is my code snippet

add_action( 'admin_enqueue_scripts', 'custom_css_stuff' );


function custom_css_stuff() {
?>
<style type="text/css">
    body { color: red; }
</style>

<?php
}
?>

This is not changing font color of body. am I missing something or is there any other way to do this?

1 Answer 1

1

If you're using the admin_enqueue_scripts hook, use wp_enqueue_script() to enqueue a CSS file with the styles you want to apply.

If you want to output a <style></style> element use the admin_head hook to output it between the <head></head> tags:

function custom_css_stuff() {
    ?>

    <style type="text/css">
        body { color: red; }
    </style>

    <?php
}
add_action( 'admin_head', 'custom_css_stuff' );
2
  • hi @jacob, Thank you for reply, I tried this code but it's not working anything else I need to do to run this code? Aug 6, 2017 at 13:58
  • 1
    Make sure your CSS is actually correct. Your styles are probably being overwritten. Make sure your rules have higher specificity than the default CSS. Aug 6, 2017 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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