14

Is there a way to override the styles in the admin in my theme?

I don't want to touch the admin style sheet if I don't have to.

I just want to make a column bigger in my admin, but also, to do it in a way that doesn't get overridden in a future wordpress update.

3 Answers 3

26

Take a look here at the CODEX for an example on how to do this very thing.

Example: Load CSS File on All Admin Pages

function load_custom_wp_admin_style(){
    wp_register_style( 'custom_wp_admin_css', get_bloginfo('stylesheet_directory') . '/admin-style.css', false, '1.0.0' );
    wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action('admin_enqueue_scripts', 'load_custom_wp_admin_style');

Example: Target a Specific Admin Page

function my_enqueue($hook) {
    if( 'edit.php' != $hook )
    return;
    wp_enqueue_script( 'my_custom_script', plugins_url('/myscript.js', __FILE__) );
}
add_action( 'admin_enqueue_scripts', 'my_enqueue' );
3
  • Does the css I create "add" to the current admin style? I only need to override 1 style so I don't want to have to skin the entire admin side... Commented Mar 7, 2012 at 15:38
  • correct, it adds to the already existing styles
    – The Z Man
    Commented Mar 7, 2012 at 15:47
  • this worked fine. I'll just add that more modern way to give path to stylesheet is get_stylesheet_directory_uri() instead of get_bloginfo('stylesheet_directory')
    – yitwail
    Commented Feb 23, 2013 at 18:02
3

You can use the admin_enqueue_scripts hook in combination with wp_enqueue_style in a manner similar to this:

// you may want to wrap add_action() in a conditional to prevent enqueue on every page
add_action( 'admin_enqueue_scripts', 'wpse44753_admin_enqueue' );

function wpse44753_admin_enqueue() {
    wp_enqueue_script(
        'wpse44753_style',
        'script/location/here.css', // you probably want to use plugins_url() for this
    );
}
0

What about using "add_editor_style( array|string $stylesheet = 'editor-style.css' )" ?

"The parameter $stylesheet is the name of the stylesheet, relative to the theme root. It also accepts an array of stylesheets. It is optional and defaults to ‘editor-style.css’.

This function automatically adds another stylesheet with -rtl prefix, e.g. editor-style-rtl.css. If that file doesn’t exist, it is removed before adding the stylesheet(s) to TinyMCE. If an array of stylesheets is passed to add_editor_style(), RTL is only added for the first stylesheet."

/**
 * Registers an editor stylesheet for the theme.
 */
 if ( ! function_exists( 'ns_admin_custom_css' ) ) : 
 function ns_admin_custom_css() {
    add_editor_style( get_stylesheet_directory_uri() . '/assets/css/admin.css' );
 }
 add_action( 'admin_init', 'ns_admin_custom_css' );
 endif;
1
  • admin_init is not correct here.
    – Foysal
    Commented Sep 27 at 11:17

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.