在 Wordpress 中创建禁用包装内容上的 wpautop() 的简码?

Create shortcode in Wordpress that disables wpautop() on wrapped content?

希望将图形放置在与这样的 h3 标题相同的 line/row 上:

<h3 style="display:inline;">Graphic Advantage</h3><img style="max-width: 50px; width: 100%;" src="https://sgdesign.com/images/SGDadvantage.png" alt="SGD Advantage"  />

首先我将 h3 display = inline,这样它只占据它的实际宽度而不是整行。我可以将 h3 和图形向左浮动,然后进行 clearfix,但它似乎过分了。目标是简单地将 h3 和小图形放在同一行上。

由于Wordpress的自动格式化功能wpautop()自动设置,段落标签

但是当次要内容(图形)包含在短代码中时,这仍然有效:

<h3 style="display: inline;">Advantage SGDesign</h3>
[tooltip text="Throughout our site you'll see this icon that will help identify significant differences between SGDesign and other companies"]<img style="max-width: 50px; width: 100%;" src="https://sgdesign.com/images/SGDadvantage.png" alt="SGD Advantage"  />[/tooltip]

问题:在某种类型的包装标签内阻止 wpautop() 函数的最佳做法?

也许会创建一个空简码,例如

function no_wp_autoformat_shortcode() {
return null;
}
add_shortcode('nowpautop', 'no_wp_autoformat_shortcode');

这会起作用,但现在它隐藏了包装的 < img ...

所以问题变成了如何在用简码包裹时显示图像?

<h3 style="display:inline;">Graphic Advantage</h3>[nowpautop]<img style="max-width: 50px; width: 100%;" src="https://sgdesign.com/images/SGDadvantage.png" alt="SGD Advantage"  />[/nowpautop]

有一种方法可以阻止 Wordpress 编辑器使用 remove_filter( 'the_content', 'wpautop' ); 自动添加 <p> 元素。不利的一面是禁用 wordpress 中的所有 <p> 元素,这在对文本进行分段时效果不佳。 (当人们从 word 文档中剪切和粘贴文本时也会出现问题...)

是的,使用短代码对我来说似乎很好,而不必覆盖 Wordpress 核心功能

通过创建一个使用链接文件 src 作为属性的简码解决。详情在这里:

主要问题是短代码替换了内容,因此不能简单地 "wrap" 一个元素来创建禁用自动格式 wpautop() 函数的预期效果。