Allow Span Tag in WordPress Editor

We’ve been using WordPress for over a year now on our site and quite frankly we love it! But as with everything in life nothing is perfect, unfortunately this is true for WordPress too.

One of the biggest annoyances we’ve encountered with WordPress has been the way TinyMCE handles your HTML source code when switching between Visual and HTML views and saving when using the editor, tags would be removed, empty <div>’s and <span>’s would be removed or converted to <br /> tags,  it just doesn’t make sense why this continues to be the default behaviour in WordPress or why there isn’t a simple option in the Settings > Writing or Users > Profile pages to enable a truly free writing/coding experience.

This short bit of PHP code should be put into your themes functions.php file

<?php
function override_mce_options($initArray) 
{
  $opts = '*[*]';
  $initArray['valid_elements'] = $opts;
  $initArray['extended_valid_elements'] = $opts;
  return $initArray;
 }
 add_filter('tiny_mce_before_init', 'override_mce_options'); 
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s