Preserved HTML Editor Markup
This plugin preserves the user-generated HTML markup in the TinyMCE editor. Unlike other plugins this one allows developers to work in the HTML tab AND end-users to work in the WYSIWYG Visual tab at the same time! No longer will your HTML markup be completely munged into an unrecognizable form when you switch between those tabs. And you don’t have to hang your users/editors out to dry when you hand off the project with a disabled Visual tab. IMPORTANT: Please read the installation instructions carefully. If you have existing content it will not render properly after activating this plugin until you use the Fix It Tools. (One user didn’t read or follow these steps and panicked thinking I ruined their website.) It also supports HTML5 Block Anchor tags in addition to other HTML5 elements, something that is currently not supported in WordPress via any existing plugins. Version 1.5 will probably be the last version I release for a while since my daughter will be born soon. I’ve added support for full JavaScript code blocks in the HTML tab. They are compatible and preserved when switching to Visual mode. This rounds out the support for almost complete html preservation, with full use of the WYSIWYG editor. And you don’t need to wrap comment codes around it per the recommendations located here: https://codex.wordpress.org/Using_Javascript but you can leave them in if you want. Version 1.4 was just a minor patch release. User @denl noticed a problem with the plugin CataBlog which implements its own administrative management features by disabling the ‘show_ui’ flag for its custom post type. I was ignoring any custom post type that didn’t have a GUI, but it was an unecessary filter that probably limited other plugins. This fix allows any post type that supports the TinyMCE editor to be “fixed” using the tools under Admin > Settings > Writing. Since version 1.3 you can now use inline CSS and JavaScript in the HTML editor and everything should be preserved. To be clear, this applies to tags only, like onclick events and style definitions – not script blocks themselves. To enable this feature you must disable the wptexturize and convert_chars filters by adding the following code to your theme’s functions.php: remove_filter("the_content", "wptexturize"); remove_filter("the_content", "convert_chars"); This new feature is pretty experimental at the moment. I tried to make it compatible with wptexturize but that proved close to impossible without duplicating a lot of core code in my plugin. It’s also not compatible with TinyMCE Advanced when the “stop removing p and br tags” setting is enabled. I’ve tested it on a variety of code samples and I’m pleased with the results but if you find any content that isn’t preserved just open a support ticket and I should be able to fix it. Since version 1.2, you now have a little more control over how content is created. And most of the previous caveats to using this plugin are now resolved. You can now choose whether to use BR tags OR P tags for newlines. Even better you can use both, where one return key press injects a BR tag, and two return key presses will wrap a Paragraph tag. This is great for being able to wrap headers at specific break points all while enjoying the semantic perks of paragraphs. In addition to choosing what type of tags to use, you can also change the behavior depending on the type of post, including custom post types. So Pages can default to BR tags, and Blog Posts can default to Paragraph tags. If you have existing content that was created before activating this plugin, you can now use the Fixit feature to convert your existing content in a way that makes it render the same as before. Only use this feature (located under Admin > Settings > Writing: Fixing Existing Content) if you are installing this plugin for the first time, otherwise it will remove all of the formatted white space in your posts. Multi-line HTML comments are now supported (Thanks to @cwlee_klagroup for suggesting the working fix!) The Format drop down in the TinyMCE editor had a bug which is now fixed. It will now select “Format” if you place the cursor on a section of bare text. Currently the editor just leaves the previously selected format option in place. It’s minor but it’s good to know when you have bare text in your content. There was a fairly problematic bug in the old version where in some browsers you couldn’t change the formatting of a single line in the Visual editor if you started from scratch. Choosing a different Format option would change the entire document, with the only work around being to edit the document in HTML mode. That was bad, and somehow went unnoticed for far too long. Anyway, that is fixed now. The caveats that still remains are: With script blocks added to your HTML markup, the right arrow key does not pass over them in the Visual Tab. You can down arrow over them however so this will likely never be addressed. If you use the Paragraph tag setting for newlines there is a minor bug where it will only wrap your content in Paragraph tags if you specify Paragraph in the Format drop down or if you enter more than one paragraph of text. So if you just type one sentence and click save it will not wrap the content in Paragraph tags. I tried to fix this but ran out of my allotted time working on other core issues. Should be fixed in the next release. For performance reasons, it will only preserve spaces if 4 spaces are used consecutively – i.e. an expanded tab in developer terms. It will not preserve intra-tag white space like . If you do add 4 or more spaces inside of an element tag it will corrupt the markup and mangle the output. But as this is intended for developer edits, this should be an extreme rarity given the habit is virtually non-existent in development communities. PRE tags are not affected and behave as you would expect, however due to how browsers parse tags, the first newline in the content of a PRE tag will be wiped out unless it is padded with either another new line or multiple spaces. CODE tags are not preserving white space at all, and when wrapped with PRE tags white space is still removed. I’m working to resolve this problem. Arbitrary section
Top keywords
- tags14×1.26%
- content12×1.08%
- html9×0.81%
- now9×0.81%
- editor7×0.63%
- paragraph7×0.63%
- tab6×0.54%
- type6×0.54%
- version6×0.54%
- code5×0.45%
- existing5×0.45%
- fix5×0.45%
TinyMCE Custom Styles
Please someone take over maintaining this plugin, or it will get abandoned – with over 9.000 active installations. I’m now 69 and although retired, all my time is taken up with other projects, while I still have the energy for them. Why you might want to take it over? It’s really useful: Make your editing experience as simple and good as possible by improving the way you work with the TinyMCE visual editor (including Gutenberg Classic block). This plugin adds custom CSS file(s) to the frontend and to the TinyMCE editor; and it allows you to populate TinyMCE’s ‘Formats’ dropdown with your own styles. The features in more detail: 1. Installs two CSS stylesheet files into your chosen location (so you can still do updates of the active theme and this plugin and even switch to another theme). In general you will need to fetch the auto-created stub files via FTP, edit them locally and upload them, overwriting the previous versions. editor-style.css is used for styling your TinyMCE Editor editor-style-shared.css is used for styles to be used by the frontend AND in your TinyMCE editor (so you do not have to copy) To use this feature, you have to write your own CSS code into these files. 2. The main feature of this Plugin is to offer a Backend-GUI to create custom styles for TinyMCE (‘Formats’ dropdown) dynamically. Easy to add, change and delete styles No editing of source code required (excepting the CSS stylesheets) Allows you to add block- and inline elements which are not provided by TinyMCE, e.g. , , etc. The plugin’s backend page contains a lot of description and some links to help you define your styles correctly Note that each style can have both CSS Classes and/or CSS Inline-Styles. The latter (excepting color) will even be applied to the Formats dropdown menu items. However, I do not recommend inline styles as they are inserted into the text of the post/page and remain unchanged if you later alter the style in the plugin settings – so in general stick to Classes! How the two stylesheets are applied The shared style sheet file is enqueued to be included on frontend pages (via the usual tag in the area) using the standard WordPress function wp_enqueue_style. So, as with most other stylesheets, the statements in it will automatically apply to the whole HTML page. So define class names which will not collide with any already in use by the theme – and do not define styles for HTML elements without a limiting class name unless you want them to apply to all elements of that tag type (including in header, footer, sidebar…). Both stylesheets are passed to TinyMCE by calling: add_filter(‘mce_css’, …) What this causes to happen is that they are linked in to the HTML document which is the source for an , which is the editing area of TinyMCE. So they should definitely only apply to HTML in the iframe – although I have heard that some situations, e.g. a cache plugin, may break this mechanism. Gutenberg classic blocks As of version 1.1.1 this plugin works for the Gutenberg classic block. WordPress MultiSite Although it does not check for MultiSite, the plugin works in the MultiSite environment, since WordPress uses a separate Options table for each MultiSite. You can reuse the same CSS files (by supplying the same custom directory in each Site), or add separate ones for each Site. Current Languages – en_US – de_DE (Tim Reeves) Background Information Then and Now This plugin was originally written by David Stöckl in 2013 – long before Gutenberg had been conceived, and at a time when several different plugins all tried to enhance the TinyMCE editor in different ways. It was abandoned a year later by David and I forked it in 2016, renamed to TinyMCE Custom Styles” (“TCS”). Most of those other TinyMCE-related plugins, notably WP Edit, are now abandoned; apart from this plugin, only TinyMCE Advanced, now also handling Gutenberg and renamed to Advanced Editor Tools (abbreviated hereafter to “AET”) seems to still be notably active in this area. AET is a great plugin – you can also check out its companion for developers Advanced TinyMCE Configuration. I use AET myself on most websites – but there are a few things it’s not designed to do, and that’s where this plugin fills the gap. You can consider it as AET’s sidekick 🙂 TinyMCE and the WordPress theme The goal is to configure the TinyMCE backend editor so that its ‘Visual’ tab displays content as closely as possible to how it will look on the content area of the actual website. To this end, WordPress has for years provided a feature which can be used by themes, called ‘editor styles’. This allows a theme to make known to WordPress one or more CSS files, which should contain a subset of the theme’s styles, those which apply to the display of content in the content area (i.e. excluding styles applying to headers, sidebars, footers, archives, comments, …). If the theme provides this feature, that CSS file (or files) are loaded to TinyMCE to achieve the goal. The default location is one file named ‘editor-style.css’ in the theme’s root directory. In fact, WordPress seems to find this file, if present, even if the theme does not register it. All good modern themes provide this feature. Advanced Editor Tools The really good plugin ‘Advanced Editor Tools’ (“AET”, from and maintained by Andrew Ozz, a WordPress core developer, now attributed to Automattic, the company effectively behind WordPress) helps with one of the problems noted above: It gives you complete freedom to select which buttons and dropdowns are displayed in TinyMCEs header – in particular you can just drag the ‘Formats’ dropdown into one of the bar areas, exactly where you want it. AET also has a number of other options, for example to prevent TinyMCE from removing tags and minifying the text in the ‘Text’ tab, which is very useful when you need to look at the HTML and do any manual adjustment. Shortcomings in the standard setup There are some regrettable weaknesses in the unenhanced situation: Any custom CSS which you set in the WordPress Customizer is not applied to TinyMCE (it is written out as direct styles in the of each website page). The styles which the theme provides for TinyMCE are applied to the HTML displayed by the editor. This is fine with fixed styling of elements like , or . But a theme may also include optional styles to change or enhance the display of an element – e.g. ‘.small’, ‘.screen-reader-text’, ‘.beforelist’, ‘.hilitebox’ and so on. In this case, and without help from any plugin, there is no way to select any of them from the menu or toolbar of TinyMCE in order to apply them to an element, so a user would need to know the style names and apply them manually in the ‘Text’ tab – not good. See below ‘importcss’, but note that it overwrites anything other plugins have put in the ‘Formats’ dropdown. In the standard configuration (i.e. without enhancer plugins) TinyMCE is not even configured to show the ‘Formats’ dropdown, which we need to apply custom styles to elements in the text. The TinyMCE Formats dropdown Internal name: ‘styleselect’. By default, this dropdown is not displayed. You can add code e.g. to your theme’s functions.php, to have it shown. Its default contents are 4 entries with corresponding submenus: Headings, Inline, Blocks and Alignement. TCS always registers the ‘Formats’ dropdown to TinyMCE’s second toolbar, this does not seem to be a problem for AET. It is in this area that TCS is really usefull: It allows you to create named styles, so you can name them descriptively, e.g. to show if the style is a block or inline style, if it uses the Wrapper option, and so on. Basically you will be adding styles to the dropdown which are defined in a stylesheet from the theme, or in your ‘editor-style-shared.css’, to allow you (or your customer) convenient and understandable access to them while editing. The TinyMCE JavaScript plugin ‘importcss’ When the AET plugin is active, it offers an option “Create CSS classes menu” (subtitle: Load the CSS classes used in editor-style.css and replace the Formats menu). When checked, a TinyMCE JavaScript plugin called ‘importcss’ is loaded to the frontend, which parses the CSS loaded to TinyMCE (i.e. from your theme’s ‘editor styles’ and this plugins ‘editor-style.css’) and populates the ‘Formats’ dropdown with a selection of those styles. Styles applying directly to HTML elements without a class name are skipped. Styles applying to a tag and containing a class, e.g. “h1.page-title” will be included and work as expected. But for classes not limited to a tag, it has no way of knowing if the class is intended to be applied to a block element or as an inline element, nor to which tags it should apply or should use, so it simply offers them as inline elements, which may or may not be their intended use. Styles with a pseudo-class or pseudo-element (e.g. ‘:hover’, ‘::before’) will be omitted. The bottom line is, that however good the themes editor styles are, we end up with a sub-optimal population of the Formats dropdown: It will be too long (including many styles we don’t need or don’t understand), and some valuable styles will be missing or wrongly classified as inline styles. Given all these shortcomings, I have not found this feature to be of much use in practice. Credits This plugin is a fork of TinyMCE Advanced Professsional Formats and Styles which has been abandoned by the original author. Initially I just fixed a JavaScript bug so that it worked again, and cleaned up the code and messages a bit. Since then, a number of further improvements, see the changelog. I was born in 1954 and would be glad if someone else would now take over this plugin and further improve it. Translations are also very welcome. David Stöckl, Vienna, the original author. Many thanks! The plugin icon (Der Bitkönig) was drawn by Gabriele Meischner, muchas Gracias! Rawrly for providing security updates. Report Security Bugs Please report all security bugs found in this project by following the vulnerability disclosure process.