WordPress remove empty span tag

I am using a WordPress editor and I want to display an icon inside a "span" -tag like this:

<div id="question1" class="box-around">
   <div class="box-left"><span class="fa fa-search" aria-hidden="true"> </span></div>
   <div class="box-right">
      <h3>Some Heading</h3>
      Some Text
      <span id="question1-answer"> </span>
    </div>
</div>

      

Whenever I make changes to "visual" it removes the "span" -tag and looks like this:

<div id="question1" class="box-around">
  <div class="box-left"></div>
   <div class="box-right">
      <h3>Some Heading</h3>
       Some Text
       <span id="question1-answer"> </span>
    </div>
</div>

      

Oddly enough, the range at the bottom (id = "question1-answer") is preserved. Am I missing something? I already tried to set the "& nbsp" space inside the tag to be converted to "(actual white space) after changing the text in" visual "and use different tags as well.

Thank!

+3


source to share


2 answers


Add this code to your active theme's functions.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');

      

+4


source


A little more specific is to allow empty tags if they have an id, name, class, or style attribute:

function override_mce_options($initArray) {
  $opts = '*[id|name|class|style]';
  $initArray['valid_elements'] .= ',' . $opts;
  $initArray['extended_valid_elements'] .= ',' . $opts;
  return $initArray;
}
add_filter('tiny_mce_before_init', 'override_mce_options');

      



Maybe I am doing something wrong, but it works for me. However, I'm sure there is a better solution - it would be nice to add only one specific tag to the valid elements.

0


source







All Articles