Short answer: yes. This has been available for quite some time but don’t think I’ve seen themes that do it. Things like typefaces, headings, image padding and borders, etc. can easily be set by the current theme making the visual editor… more WYSIWYG. All it takes is a stylesheet and a small function in the theme’s functions.php file:
add_filter('mce_css', 'my_editor_style'); function my_editor_style($url) { if ( !empty($url) ) $url .= ','; // Change the path here if using sub-directory $url .= trailingslashit( get_stylesheet_directory_uri() ) . 'editor-style.css'; return $url; }
where editor-style.css will be applied to TinyMCE’s iframe.
There is also an option to define CSS classes that can be inserted by the user and to add the “Styles” drop-down selector to the editor toolbar. This is probably most useful for developers when creating a custom theme for a client as these classes would stop working if the theme is changed.
I’ve put together a small package with examples of how to enable this. If you are creating WordPress themes, download it or have a look, it’s quite simple. If not, perhaps ask the author of your theme to add it to the next update. 🙂
Update: as Dion points out in the comments, this is not meant for adding the whole “style.css” to the editor. That could bring problems and most of the styling won’t apply there anyways. It works best when a separate stylesheet is made specifically for use in the editor (editor-style.css in the example). It should contain a small subset from style.css, usually the part that is applied to the actual posts.
Holy cow! That’s awesome!
Thanks for the tip 🙂
Would be great if you make a post / code on how to add buttons to the editor
Ajay, I have an article on how to add Quickedit buttons on my site. I won’t hijack the thread with a link, but you should be able to find it if you look.
It’s not difficult, but getting it right the first time can be tricky.
Slick 🙂
This sounds great, but I can’t get it to work in Thesis. Should this work if I add this code to the custom_functions.php file used by thesis? Or is the problem perhaps that I need to change the stylesheet location To reflect the fact that thesis places all the custom files in wp-content/themes/thesis_16/custom/ ?
I tried this but it didn’t work:
get_stylesheet_directory_uri.$custom() )
Berin: This doesnt work too well if you use the entire stylesheet, The idea is that you would use a smaller subset of your main themes CSS in a different stylesheet specifically for the editor.
Pingback: Andrew: Can themes style the visual editor? - wpparty.com
Amazing how such a small piece of code can be so powerful. I’ve created my fair share of wordpress themes, but I’ve never touched the admin area of WordPress. Maybe this will be the first step?
thanks…
There is edit toolbar. this is very good and easy There is also an option to define CSS classes that can be inserted by the user and to add the “Styles” drop-down selector
Good to know! I will have to give it a shot. =)
This is great Andrew! In the past I’ve had to say to clients: “This is the way it looks here, but it will look different when it’s actually posted (vastly different)…” I can’t wait to get this going on my custom themes!
Pingback: links for 2010-01-05 | Digital Rehab
Pingback: WordPress Tutorials
Pingback: links for 2010-01-04 « Mark Thomas Gazels websted
Pingback: WordPress Picks for the Week [01/03] | Techtites
Thanks for this!
Does anyone how to serve up a different stylesheet in tinymce’s fullscreen mode? The fullscreen iframe’s id is mce_fullscreen_ifr, but since the stylesheet’s loaded *inside* the iframe, I can’t distinguish between the two in the stylesheet itself.
This is so awesome. I hate having to tell clients, no it wont look like that when you publish. It doesnt make any sense… what a great fix. It works great, and I haven’t even tried the kit files yet (just tested the function to start with)
Question. Would a horizontal rule tag work in the kit?
Pingback: WYSIWYRG | 2010 Theme Development
Wow. Definitely going to check this out and implement it in upcoming themes!
Had no idea. Thanks!
Pingback: Tip: Make your theme WYSIWYRG compatible by Free WordPress Themes Blog
Pingback: Today in WordPress world – 10/02 | Links | WereWP
Pingback: De WYSIWYG editor bij je theme laten passen | Hiranthi's weblog - Weblog van een ondernemende vrouw
I was really excited when I found this tip. Thanks for pointing it out. I’m happy to report that WordPress 3.0’s default theme will be making use of it. There’s a bit more information about it on the twentyten dev blog.
Good to know! I will have to give it a shot. =)
I got this to work with the editor which was awesome! But I notice that when I use the search pages feature in the pages section, I get this error code:
Warning: Cannot modify header information – headers already sent by (output started at F:\XAMPP\xampp\htdocs\wp-content\themes\accelera\functions.php:515) in F:\XAMPP\xampp\htdocs\wp-includes\pluggable.php on line 868
When I remove the function from functions.php I am able to do the pages search without issue. Is there a fix or can you explain what I’m doing wrong?
And actually I get the same error when I try to update a page. What am I doing wrong?
This is great Andrew! In the past I’ve had to say to clients: “This is the way it looks here, but it will look different when it’s actually posted (vastly different)…” I can’t wait to get this going on my custom themes!
Pingback: Twenty Ten: The New and Improved Default WordPress Theme | BloggingPro
Pingback: 8 useful code snippets to get started with WordPress 3.0
Pingback: 8 useful code snippets for WordPress 3.0 | 610 Design
Pingback: Editor “totalmente” WYSIWYG | Ayuda WordPress
Pingback: Editor “totalmente” WYSIWYG | Ajuda Wordpress em Português
Pingback: 8 Useful Code Snippets To Get Started With WordPress 3.0 | WPGrind.com
Pingback: WYSIWYRG | West of the Eastern Shore
I wish this were simple enough for a common user of 1 year like me – I used Redoable Lite and, of course, the visual editor bears almost no resemblance to what Preview shows if you include images, say.
I hope someone can translate this into simple enough language for someone who’s never touched a style sheet, never written a line of php, never defined a CSS class. Needs to be a path for us who’ve not done these things to get to a nearly WYSIWYG visual editor.
Is it a goal to have every theme “nearly WYSIWYG” b/c the way it is now is very, very frustrating as I constantly go between preview and edit.
I’m sure there will be a plug-in for this shortly to ease the pain of activating it, but there will always be the need to separate your CSS correctly so that you do not completely reload the entire site’s CSS into the editor iframe. Ideally, so that the DRY (Don’t Repeat Yourself) principle is maintained, the CSS that relates to posts should be separated out into a separate style sheet so that it can be targeted by my_editor_style hook and then to not repeat those CSS rules within styles.css, use the @import CSS declaration to import those post-specific styles into the main theme stylesheet.
Pingback: Wordpress 3.0 Insight – main features and settings
Pingback: 主题功能扩展:自定义 WordPress 默认编辑器样式 | Dreamcolor's Cote
Pingback: WordPress | Slovensko » TwentyTen: Nový a vylepšený základný vzhľad WordPress
Pingback: Completo editor visual en Wordpress | Dinero 2.0
Pingback: Feed-Syndicate » Blog Archive » 8 useful code snippets to get started with WordPress 3.0
That is amazing! I can’t wait to implement this.
Pingback: 覚え書き Wordpress3.0 新機能 « SIDE_FLIP blog
Pingback: Wordpress 3.0 en español | Blog TenTuLogo
Pingback: Why Your Visual Editor Width is Different in WordPress 3.0WP Modder | WP Modder
Hi, a question a bit out of topic, but I can’t find a solution to it.
I use your wp-plugin Top Comments and can’t seem to find a way to clear the votes in the widget. Have cleaned the database but no success?
The votes don’t disappear when i trash the comments.
Pingback: 8 useful code snippets to get started with WordPress 3.0 | Faredigitale
This is great but there’s one further step I’d like to take – I’m sure it must be simple but I can’t quite work it out!
My page space is limited to 664px wide and a lot of the layouts rely on that measurement to make sense.
Is there a way of forcing the TinyMCE editor window to this width?
Pingback: Twenty Ten, a New Default Theme for WordPress — ForSite Media
Pingback: Осваиваем новые функции WordPress 3.0 « defreshen
Pingback: Меняем вид редактора WYSIWYG с помощью CSS | WebteamDesign.ru
I really like this idea, but I can’t seem to get it to work. Running WP 3.0. I’ve added the code to functions.php and I’ve added a reduced stylesheet to the same folder as the original stylesheet, but it doesn’t seem to have any effect on the editor. How could I troubleshoot to make sure that the new ‘editor-style’ is being found?
After edits and uploading, I sparingly snipped barebones css from my styles.css into editor-style.css. I began with font, font-size, content width, borders and background to help visualize layout. Very exciting. Kudos to the WordPress team. But I think there’s work ahead.
I found that TinyMCE did not precisely mirror published styles. For example, small differences in width, margin, padding, line-height and other settings significantly threw off line breaks. Good, but not a 1-by-1 match. Later I noticed image floats had broken wraps, including RSS alignment, and had failed in the editor too. There’s lots of tweaking ahead for me. Bugs ahoy!
Wow! Must really try this one. This means no more constantly clicking “Preview” to check how your post’s elements are aligning.
Great! Thanks a lot!
Pingback: 2010: Nová Základná Téma pre WordPress 3.0 | Twenty Ten
Pingback: NetzBlogR » Echtes WYSIWYG in WordPress
Thanks for this – simple enough!
I really hate that in the new WordPress Twenty Ten Theme. There’s a limited with in the editor, and i think think this is really confusing and irritating for some users
Pingback: How to style the WordPress TinyMCE WYSIWYG visual editor | WP Journo: WordPress CMS & Journalism
Just wanted to say thanks for offering that package of examples. It helped a lot to be able to see those examples and doesn’t seem as hard as I thought it would be.
Pingback: Shun the Plugin: 100 WordPress Code Snippets from Across the Net | WordPress, Multisite and BuddyPress plugins, themes, news and help – WPMU.org
Pingback: SFCite | Blog | Shun the Plugin: 100 WordPress Code Snippets from Across the Net
Thanks for the excellent post! I’d also like to contribute a couple more things that I found made this even more powerful:
1. Similar to what R’phael Spindel said in his comment about using the DRY principal, I separated the content-related styles from the style.css so that I don’t have to add/edit css rules in 2 places. So I have an additional stylesheet ‘content.css’ and my theme loads this file using wp_enqueue_style(). I chose this over @import as I think it will yield better performance.
2. mattm asked how to force the TinyMCE to display using the same width as your theme’s content. I did this by adding the following to my content.css (comments added for clarity):
body.mceContentBody {
width: 590px; // The same width that the theme sets for content
margin: 0 auto; // This is just to make it centered in the TinyMCE editor
padding: 10px; // Padding and borders just to give a visual cue while editing
border-right: 1px solid #DDD;
border-left: 1px solid #DDD;
color: #333333; // Setting the text color, size, font to match the theme
font-size: 12px;
font-family: Arial, Tahoma, Verdana;
}
Thanks for the excellent post. I was able to get this to work fairly easily. Very helpful!
Pingback: 8 полезных кодовых сниппетов для WordPress 3.0 | Очередной блог фрилансера
Really great plugin, thank you very much for it.
Kind regards!
Pingback: Style the Visual Editor with Themes » Wordpress Tutorials
Pingback: 101 Useful WordPress Snippets | Resources and Tools