php - WordPress 不断向短代码和内容添加自动段落标签

标签 php html wordpress shortcode

我似乎无法阻止 WordPress 自动向我输入的每一行添加段落,包括短代码和我输入到视觉编辑器中的任何原始 HTML。我尝试过使用插件“Toggle wpautop”和“Raw html”来尝试转换它,但它从来没有工作过。是因为我使用的是视觉 Composer 吗?它只是将 p 标签包裹在任何东西上。

enter image description here

最佳答案

问题不在于 Visual Composer,它的发生纯粹是因为 autop 过滤 the_content 。有几种方法可以解决这个问题,但恕我直言,内容过滤器是最好的处理方法。

如果您愿意编辑functions.php,您可以过滤the_content钩子(Hook)移除<p>包含 strtr 的短代码标签添加以下内容:

add_filter('the_content', 'remove_unneeded_silly_p_tags_from_shortcodes');
function remove_unneeded_silly_p_tags_from_shortcodes($the_content){
    $array = array (
        '<p>['      => '[', //replace "<p>[" with "["
        ']</p>'     => ']', //replace "]</p>" with "]"
        ']<br />'   => ']' //replace "]<br />" with "]"
    );
    $the_content = strtr($the_content, $array); //replaces instances of the keys in the array with their values
    return $the_content;
}

其他替代方案( like removing autop from the_content )往往会产生相当深远的影响,所以我倾向于避免这种情况。您还可以尝试从添加的特定段落标签中删除边距样式,但由于自动添加,可能很难定位该特定标签...

关于php - WordPress 不断向短代码和内容添加自动段落标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51316972/

相关文章:

HTML 布局 - 左侧 1 个,右侧堆叠 2 个

html - 单击另一个链接时标题中出现奇怪的图像移动(仅出现在 IE 中)

mysql - 连接到 mysql 的问题,随机数据库连接错误,

php - 我的脚本有什么问题吗?

php - WordPress 查询根据自定义表获取帖子

html - 仅适合一个全屏的背景图片

git - 使用 Git 更新 WordPress 的多个安装

php - WordPress 站点的 Linux/PHP 服务器设置

php - 高级正则表达式替换。检查是否在 &lt;script&gt; 标签中

php - 多个 mysqli 数据库连接,不好的做法?