{"id":83538,"date":"2012-06-28T12:00:23","date_gmt":"2012-06-28T16:00:23","guid":{"rendered":"http:\/\/wpmu.org\/?p=83538"},"modified":"2012-06-27T15:14:07","modified_gmt":"2012-06-27T19:14:07","slug":"wordpress-editor-stylesheet","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/wordpress-editor-stylesheet\/","title":{"rendered":"Improve WordPress Visual Editor for any theme with Editor Stylesheets"},"content":{"rendered":"<p>What good is a <a title=\"Why You Hate The WordPress Text Editor and What To Do About It\" href=\"https:\/\/wpmudev.com\/blog\/why-you-hate-the-wordpress-text-editor\/\" target=\"_blank\">WYSIWYG editing interface<\/a> if it fails to show what your marked-up content really looks like? Many themes do not make use of editor styles, even though they\u2019ve been available since WordPress version 3. Let\u2019s cover how to:<\/p>\n<ol>\n<li>Enable editor style sheets in your theme.<\/li>\n<li>Tell your theme to acknowledge the editor style sheet.<\/li>\n<li>Then port over your theme\u2019s post CSS to make your editing screen snazzy (and correct.)<\/li>\n<\/ol>\n<h2>Editor stylesheets: an egg is an egg<\/h2>\n<p>Editor stylesheets allow the Edit Post screen&#8217;s content area to use special styles for the WYSIWYG editor. By building a correct stylesheet based on a WordPress theme&#8217;s main stylesheet, the editor can show exactly what different elements will look like on the published page.<\/p>\n<h2>Been there, done that<\/h2>\n<p>Hacks for properly styling the edit screen&#8217;s content have been around for some time. WordPress version 3 brought the \u201c<a href=\"https:\/\/wpmudev.com\/blog\/daily-tip-change-the-style-of-the-default-wordpress-post-editor\/\" target=\"_blank\">add_editor_style<\/a>\u201d functionality to make it even easier. Despite all this, many otherwise wonderful themes still leave content in the editor window styled with WordPress defaults.<\/p>\n\n<h2>Examples of themes with and without support.<\/h2>\n<p>The <a href=\"https:\/\/wpmudev.com\/blog\/extend-wordpress-twenty-eleven-theme-to-include-sidebars-and-more-flexible-options\/\" target=\"_blank\">2011 theme<\/a> that ships with WordPress supports editor stylesheets. Compare the editor content area with the same content in the published page. Pretty neat!<\/p>\n<p>The \u201ctypebased\u201d theme\u2014a great looking free theme\u2014does not support editor stylesheets. Again, compare the editor and published page screen.<\/p>\n<h2>How to add editor stylesheets to any theme<\/h2>\n<p>With a little work, you can add editor stylesheets to any WordPress theme. Some themes may be more difficult than others\u2014based on the CSS file&#8217;s quality\u2014but the process is always the same.<\/p>\n<p>Watch the video below to see this process, every step of the way. If you prefer text, you can find it below.<\/p>\n<p><span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><span class=\"embed-youtube-lazy-id dev-hidden\">fNgjvtr4Rk4<\/span><\/span><\/p>\n\n<h3>Step-by-step instructions:<\/h3>\n<ol>\n<li>Add a new file called \u201ceditor-style.css\u201d to the theme directory.<\/li>\n<li>In the theme&#8217;s \u201cfunctions.php\u201d file, add \u201cadd_editor_style();\u201d line so WordPress will look for that new stylesheet you just made when using the editor.<\/li>\n<li>Prepare a sample post that contains all the elements you need to style. I recommend your post contain the following elements:\n<ol>\n<li>p<\/li>\n<li>strong text in a paragraph<\/li>\n<li>emphasis text in a paragraph<\/li>\n<li>h1, h2, h3<\/li>\n<li>h4 \u2026 h6 if applicable to your theme<\/li>\n<li>ul with 3 list items<\/li>\n<li>ol with 3 list items<\/li>\n<li>blockquote<\/li>\n<li>some linked text<\/li>\n<li>An image with no alignment.<\/li>\n<li>An image right aligned.<\/li>\n<li>An image left aligned.<\/li>\n<li>\u2026depending on your theme, you may need others<\/li>\n<\/ol>\n<\/li>\n<li>Add global CSS rules from your main style.css to the editor-style.css. By \u201cglobal CSS,\u201d I mean rules for basic HTML tags such as body, p, h1, h2, ul, li, etc.<\/li>\n<li>Add any direct rules for .alignleft, .alignright, and .aligncenter. These are for images, and I mention them because they are often overlooked, and sometimes not near the top of CSS files by the basic HTML tags.<\/li>\n<li>View you published page and use <a title=\"Customizing Your WordPress Theme Using Firebug\" href=\"https:\/\/wpmudev.com\/blog\/customizing-your-wordpress-theme-using-firebug\/\" target=\"_blank\">Firebug<\/a>, Chrome developer tools, or whatever you like for checking the HTML \/ CSS in your browser. (The following video uses FireBug for the FireFox browser.)<\/li>\n<li>Using Firebug&#8217;s element selector, click on the first HTML element in the page&#8217;s content to check the style rules assigned to it.<\/li>\n<li>Firebug&#8217;s CSS pane will show specific styles at the top, and move down to more general styles. The \u201cglobal CSS rules\u201d we added in step 4 above will show at the bottom of this pane.<\/li>\n<li>Add any specific styles found in the live page to the corresponding generic styles in your editor-style.css file.\n<ol>\n<li><strong>Example 1:<\/strong>\n<ol>\n<li>\u201c.post-content h2 {font-color:#eee;}\u201d discovered using Firebug on the live page.<\/li>\n<li>\u201cfont-color:#eee;\u201d needs added to the h2 rules in the editor stylesheet.<\/li>\n<\/ol>\n<\/li>\n<li><strong>Example 2:<\/strong>\n<ol>\n<li>\u201cimg.alignright {margin:3px 0 2px 10px;}\u201d discovered using Firebug on the live page.<\/li>\n<li>\u201cmargin:3px 0 2px 10px;\u201d needs added to an img.alignright rule in the editor stylesheet.<\/li>\n<li>Since there is a specific rule for img.alignright, you should also add and test a left-aligned image.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>Check the edit screen for the test page. While you will probably see your styles coming through, you might also notice some of the global CSS rules are inappropriate.\n<ol>\n<li><strong>Example:<\/strong> With typebased, we had a background-color on the body element, but we did not want this on our post-containing element. We simply remove that background color from the body element in our editor CSS file.<\/li>\n<\/ol>\n<\/li>\n<li>NOTE that if your site uses plugins that add their own CSS, and it affects items you would add and see in your editor, you need to add those CSS rules to editor-style.css as well. Firebug should still show you these rules, unless they are dynamically added via JavaScript.<\/li>\n<li>CUFON and other font replacements are not practical to implement in the WYSIWYG editor.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n\n<h2>Credits<\/h2>\n<ul>\n<li>Colorful fashion photo: <a href=\"http:\/\/www.fotocommunity.com\/pc\/account\/myprofile\/1655578\" target=\"_blank\">http:\/\/www.fotocommunity.com\/pc\/account\/myprofile\/1655578<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learn to make the WordPress WYSIWYG editing interface show a theme&#8217;s exact styles.<\/p>\n","protected":false},"author":97717,"featured_media":83674,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[34],"tags":[1044,2186],"tutorials_categories":[],"class_list":["post-83538","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-themes","tag-css","tag-wordpress-editor"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/83538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/97717"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=83538"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/83538\/revisions"}],"predecessor-version":[{"id":216433,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/83538\/revisions\/216433"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/83674"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=83538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=83538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=83538"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=83538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}