中创建在包装内容上禁用

中创建在包装内容上禁用

本文介绍了在 Wordpress 中创建在包装内容上禁用 wpautop() 的短代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望将图形放置在与 h3 标题相同的行/行上,如下所示:

Looking to place a graphic on the same line/row as an h3 title like this:

<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 和图形向左浮动,然后进行清除修复,但这似乎过分了.目标是简单地将 h3 和小图形放在同一行上.

First I make the h3 display = inline so it only occupies it's actual width rather than the full row. I could float the h3 and the graphic left and then do a clearfix but it seems excessive. The goal is to simply place both the h3 and small graphic on the same line.

它失败是因为 Wordpresses 自动格式化功能 wpautop() 会自动设置一个段落标记 <>

It fails because of Wordpresses auto formatting function wpautop() which sets automatically, a paragraph tag < p >

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

But yet this works when the secondary content (graphic) is wrapped in a shortcode:

<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() 函数的最佳做法是什么?

QUESTION: Best practice to thwart the wpautop() function within a wrapped tag of some type?

也许创建一个像

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

这会起作用,但现在它隐藏了包裹的 <图片...

This will work but now it hides the wrapped < img ...

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

So the question changes to how to make an image show when wrapped by a Shortcode ?

<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]

推荐答案

通过创建使用链接文件 src 作为属性的 Shortcode 解决.详情在这里:如何创建一个什么都不做的 Wordpress 简码?

Solved by creating a Shortcode that uses the linked file src as an Attribute. Details here:How to create a Wordpress Shortcode that does nothing?

主要问题是 Shortcodes REPLACE 内容不能简单地包装"一个元素来创建禁用自动格式 wpautop() 函数的预期效果.

The primary problem was that Shortcodes REPLACE content so could not simply "wrap" an element to create the desired effect of disabling the auto format wpautop() function.

这篇关于在 Wordpress 中创建在包装内容上禁用 wpautop() 的短代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 15:16