1

How can I copy the default styling for the admin and tell wordpress to use custom style instead of the default? Basically I want to change the colour and font without having to use !important syntax to force Wordpress to use it.

2
  • Couldn't you just enqueue your own style sheet in the admin and override the CSS you need to?
    – DaveLak
    Jul 13, 2018 at 23:37
  • @WilliamJerome If you have found the answer, share it as an answer to your question, so others can benefit. Jul 14, 2018 at 2:25

3 Answers 3

2

As noted by @Fusion, this has changed beginning with version 5. In order to override admin styles for 5.*, you need a hook in functions.php, something like this:

function custom_admin() {
    $url = get_settings('siteurl');
    $url = $url . '/wp-content/themes/my-theme/wp-admin.css';
    echo '<link rel="stylesheet" type="text/css" href="' . $url . '" />';
}
add_action('admin_head', 'custom_admin')

Sources:
Wordpress Codex
isitwp Snippet

Please note the the isitwp Snippet erroneously mixes html entitites with angle brackets. You should use angle brackets not entitieis.

1
  • Please use get_option() instead of get_settings() as that has been deprecated since 2.1.1! In fact, the "modern" best practice would be $url = get_stylesheet_directory_uri() . '/wp-admin.css';
    – Tom Auger
    Feb 6, 2022 at 21:08
1

Enqueue custom admin CSS file (custom-admin.css) in your WordPress backend using below function:

add_action('admin_print_styles', 'custom_admin_css');
add_action('wp_enqueue_scripts', 'custom_admin_css');

function custom_admin_css() {
    if (is_admin()) {
        wp_enqueue_style("custom-admin-css", get_bloginfo('template_directory'). "/custom_admin.css", false, false, "all");
    }
}

Hope this works..!!

1
  • In current 5.* version of Wordpress it "works", but if you want to add custom CSS of Wordpres's admins interface (for example a purple button), you will not move anywhere. Wordpress loads all the native admin-css as the last element of the page - meaning, that all your custom CSS will be overriden.
    – Fusion
    Mar 21, 2019 at 11:32
0

In WordPress 5.x you can use the following hooks to add CSS to either the admin pages or the post edit page.

enqueue_block_editor_assets to add your own styles to the Gutenberg page

admin_enqueue_scripts to add your own styles to the admin pages

You can add the hooks in your functions.php theme file.

1

Your Answer

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

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