WordPress 删除空的 span 标签 [英] WordPress removes empty span tag

查看:31
本文介绍了WordPress 删除空的 span 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 WordPress 编辑器,我想在span"标签中显示一个图标,如下所示:

<div class="box-left"><span class="fa fa-search" aria-hidden="true"></span></div><div class="box-right"><h3>一些标题</h3>一些文字<span id="question1-answer"></span>

每当我对视觉"进行更改时,它都会删除跨度"标签,如下所示:

<div class="box-left"></div><div class="box-right"><h3>一些标题</h3>一些文字<span id="question1-answer"></span>

奇怪的是,底部的跨度 (id="question1-answer") 被保留了下来.我错过了什么吗?我已经尝试在标签中设置一个空格&nbsp",在更改visual"中的文本并使用不同的标签后,它将被转换为"(实际空格).

谢谢!

解决方案

将此代码添加到您的活动主题 functions.php 文件中.

function override_mce_options($initArray) {$opts = '*[*]';$initArray['valid_elements'] = $opts;$initArray['extended_valid_elements'] = $opts;返回 $initArray;}add_filter('tiny_mce_before_init', 'override_mce_options');

I use WordPress-editor and I want to display an icon within 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 a change in "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 span at the bottom (id="question1-answer") is kept. Am I missing something? I already tried to set a whitespace "&nbsp" within the tag, which will be converted to a " " (actual whitespace) after changing text in "visual" and used different tags as well.

Thanks!

解决方案

Add this code in your active theme functions.php file.

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');

这篇关于WordPress 删除空的 span 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆