Support » Plugins and Hacks » Hacks » Turning Off Open Sans for the 3.8 Dashboard

  • I’m looking for a way to turn off the Open Sans font in the admin. I’m already using the code below to force the admin area to use a different font:

    function betterfonts1() {
    ?>
    <style type="text/css">
    body {font-family: Times New Roman,Times;}
    </style>
    <?php
    }
    add_action( 'admin_head', 'betterfonts1' );

    This works really well, but the Open Sans is still being called in the header. It looks like this in the header:

    <link rel='stylesheet' id='open-sans-css' href='//fonts.googleapis.com/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&subset=latin%2Clatin-ext&ver=3.8' type='text/css' media='all' />

    For efficiency I’d like to have the call be turned off completely. I’ve tried the following bit of code:

    function removeopensans() {
    	wp_deregister_style( 'open-sans' );
    }
    add_action( 'admin_enqueue_scripts', 'removeopensans' );

    And this works, but it completely removes the stylesheet so there is zero styling for all of the admin. I’ve also fiddled with the core file script-loader.php by commenting out line 634:

    // $open_sans_font_url = "//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets";

    Commenting out this bit of the core file does the trick. It turns off the open sans font call in the header but keeps the general admin styling. Is there a way to turn off the open sans font in the admin without fiddling with core files?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Sorry, I don’t have an easy answer for you. A clean solution does seem out of reach, which is somewhat surprising, as the new admin theme was supposed to be easier to skin! See http://wptavern.com/wordpress-core-adopts-sass-css-preprocessor

    I assume by skin they include fonts, it’s only logical. So far, most interest in skinning the 3.8 admin area seems to be in different color schemes, not changing fonts. You might consider taking a step back and look into how SASS could be used to alter fonts. Looking forward, we will be using SASS to make any admin theme changes, and eventually front end themes as well!

    Take a look at this concept for skinning the admin area: http://wordpress.org/plugins/the-admin-theme-experience/
    It seems silly to need to generate an admin theme just to change a font, but if changing fonts is as easy as changing colors, it may not be a big deal.

    Some people seem to be getting into SASS abstraction which I see as a mistake for a lot of WP development. So many sites are just relatively simple, and one shouldn’t have to learn some new abstraction to bog a little site down when the old standby css works just great. If they want massive abstraction, they should be using Drupal.

    Commenting out the $open_sans_font_url in the core file seems to speed up the load time of my admin pages too. I’m not an advanced programmer, but I know there’s got to be a php solution instead of altering the core file directly.

    Thank you for the plugin link, I’m looking into it now it has some things in it that might be helpful. I’ll just keep hacking on it and see where I can get.

    Here’s the skinny and some solutions depending on which direction you want to go.

    How to Replace Open Sans in WordPress 3.8

    The reason this doesn’t work:

    function removeopensans() {
    	wp_deregister_style( 'open-sans' );
    }
    add_action( 'admin_enqueue_scripts', 'removeopensans' );

    Is because most other admin styles have open-sans as a dependency. Without it, they don’t load, which is why all styles disappear.

    To get it working, you just reregister Open Sans but don’t include a source for it:

    function remove_open_sans() {
    	wp_deregister_style( 'open-sans' );
            wp_register_style( 'open-sans', false );
    }
    add_action( 'admin_enqueue_scripts', 'remove_open_sans' );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Turning Off Open Sans for the 3.8 Dashboard’ is closed to new replies.