The basic installation of WordPress 2.5.1 doesn’t enable the “clean up Word content” options of its WYSIWYG editor, TinyMCE, by default. This means that if you copy some content from Microsoft Word, it is not cleaned up when it is pasted into WordPress.

Pasting the Content

I have found that the tidying of pasted content is a very, very good thing to enable, especially for corporate users who are copying content from Word and pasting it into WordPress using Microsoft Internet Explorer. So, I have created a WordPress plugin to enable content cleanup by default. This article describes the plugin and how to install it.

The options enabled by this plugin will only work if you are pasting into WordPress using Microsoft Internet Explorer. So, if you aren’t using MSIE, then the plugin won’t be of much use to you.

The plugin enables two paste options that are normally disabled by default:

paste_auto_cleanup_on_paste
When enabled, this option means that all pasted content from Microsoft Word will be tidied up before it is pasted. This option is disabled by default in TinyMCE, but my plugin enables it.

The traditional way to use this option in TinyMCE is to add an extra button to TinyMCE, offering a special “paste from Word” option. If the user selected the “Paste from Word” option, then the content would first be tidied.

In my experience, corporate users (who are often not very fluent in Word, let alone web content management) will simply “copy” from Word, and “paste” into TinyMCE, ignoring any special “Paste from Word” option. So, my plugin enables Word tidying by default, to avoid the chance of users pasting Word content without using a special “paste from Word” option.

paste_convert_headers_to_strong
This option converts h1 to h6 elements to strong elements on paste. This option is disabled by default in TinyMCE, but my plugin enables it.

Headers Markup

I have seen several examples of corporate users creating content in Word, and correctly using Word’s “Header 1″ to “Header 6″ styles to mark up the headers in their content. Whilst this is good practice, and should generally be encouraged, it can in some circumstances lead to problems when the content is pasted into TinyMCE. By default, TinyMCE converts “Header 1″ into an h1 tag, and so on for “Header 2″ to h2 etc. This is also a good thing in theory – but in practice, it can lead to one person’s content (created in Word with “Header 1″ styles throughout) being pasted with very large h1 headers throughout, and another person’s content (created in Word using “Bold” and “font size” to indicate headers) being pasted with normal-sized strong headers in TinyMCE.

The ideal would be to train all users to create and structure their content using the appropriate multi-level header styles in Word. The reality is that it is sometimes better to convert all headers to strong tags, to cope with all levels of Word ability. The resulting web content may not be structurally ideal, but at least it is more consistent across several Word users. So, I have chosen to enable this option by default. If you don’t want to enable this option, simply delete the following line from the plugin:

$init['paste_convert_headers_to_strong'] = true;

Other options

TinyMCE offers other paste options too, which you can add into a customised version of this plugin very easily. For example, if you turn on paste_auto_cleanup_on_paste(which my plugin does – see above), then the following two options will also take effect (as their default value is to be enabled in TinyMCE):

paste_remove_spans, which removes span elements from pasted Word content
paste_remove_styles, which removes style attributes from pasted Word content

You could, for example, turn one of these options off, by adding a line such as this to my plugin:

$init['paste_remove_styles'] = false;

I prefer to leave these two options enabled. A full list of all of the paste options can be found on the TinyMCE wiki.

If this plugin sounds useful for your own WordPress installation, then you should download v1.0 of my TinyMCE Paste Options plugin. You can use the plugin in any way, and customise it in any way. The only thing I would request is that you don’t redistribute it, but link to this page instead.

Once you have downloaded the plugin, unzip the downloaded zip file, and copy the tinymce_paste_options.php file to the /wp-content/plugins/ folder of your WordPress site. You will then need to enable the plugin via the WordPress “Manage Plugins” admin interface. Don’t forget that the Word paste options only effect MSIE!