[How to] Change HTML Editor Font in WordPress
As a developer, I prefer writing my posts in HTML editor. It is strange, but TinyMCE HTML editor doesn’t use monospace fonts. Here i will show you how to insert our own CSS styles in WordPress using theme functions file.
To insert our custom css, all we need is a hook, and this hook is admin_print_styles
. WordPress call this hook before the start of Admin CSS outputs. So we will output our CSS using it. After the hook is called, all we need to do is, output our CSS wrapped with <style> tags. Here is the full working code:
function change_editor_font(){ echo "<style type='text/css'> #editorcontainer textarea#content { background: #efefef; /* A darker background is better for eyes ;) */ font-family: Monaco, Consolas, "Andale Mono", "Dejavu Sans Mono", monospace; /* The best monospace font-family stack, i think */ font-size:14px; text-shadow:0px 0px 0px #444; /* Using it because i can */ color:#444; } </style>"; } add_action("admin_print_styles", "change_editor_font");
Just copy & paste this code to your functions file, and enjoy sweetness of monospace fonts.
As you can see I used double ids for the rule (#ecitorcontainer #content). This way, i am making sure my CSS rules won’t be overwritten. You can read more about css style precedence here.
Using this template you create your own CSS modifications. But please note that this hook will work for admin pages only. For wordpress frontend css inserts, you will need to use wp_print_styles
hook.
For other functions file hacks here is the list:
- Fix Duplicate Title Tags in WordPress, SEO Tips and Usage
- [How to] Change the Default WordPress Title Separator
- [How to] Change Default WordPress Title Separator
- Remove Checkout Fields from Woocommerce Checkout Page
- Shortcode to Display Content Only on Mobile
- [How to] Redirect 404 Hits to Your Homepage in WordPress
- [How to] Find Which Page Template Is Used By WordPress
- Replace WordPress jQuery with CDN jQuery using wp_enqueue_script
- [How to] Change Number of Posts Displayed on Search Only
- [Hack] Add Browser CSS Classes to Body Using WP Filters
- [How to] Display Most Viewed Posts First on Search Results
- [How to] Make Auto-embedded Youtube Videos Obey z-index
- [How to] Exclude Categories and Tags From Widgets
- [How to] Display “Back to parent” Link on Pages
- [How to] Display Latest Tweet on WordPress
- [How to] Enable Comments for All Posts in WordPress Using PHP
- [How to] Use WordPress Shortcodes in Theme Using PHP
- [How to] Display Site Logo on Facebook if Post Doesn’t Have a Thumbnail
- How to Use “wp_enqueue_script” to Add Javascript to Theme
- [How to] Change WordPress Default Embed Size Using Filters
- How to Enable Shortcodes in Widgets for WordPress
- [How to] Disable WordPress Admin Bar
- [How to] Change HTML Editor Font in WordPress
- [How to] Change Dropdown Menu Depth and Order Using Filters
- [How to] Hide Members Only Content in WordPress
- Advanced Adsense Targeting in WordPress – Part 2