禁用 WordPress 短代码内的自动格式化
我看过有关创建(原始)短代码的教程,该短代码使其中的代码保持不变,
http://www.wprecipes.com/disable-wordpress-automatic-formatting-on-posts-using-a-shortcode
但不幸的是,这一次仅适用于一个短代码...和,因为 else
语句绕过普通过滤器并调用函数指令。我对 autop 和texturize 函数的其他修改被忽略。
有没有办法 1. 匹配多个短代码和 2. 保留我的其他添加/删除过滤器到 the_content?
I've seen the tutorials on creating a (raw) shortcode that leaves the code inside it untouched,
http://www.wprecipes.com/disable-wordpress-automatic-formatting-on-posts-using-a-shortcode
but unfortunately this only applies to one shortcode at a time... and because the else
statement bypasses the normal filters and calls the functions directions. My other modifications to autop and texturize functions get ignored.
Is there a way to 1. match multiple shortcodes and 2. preserve my other add/remove filters to the_content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在多个网站上实施 @helgatheviking 的解决方案后,我确信只需要这些行:
将它们放入您的
functions.php
文件中,然后就可以了。After implementing @helgatheviking's solution on multiple websites, I'm convinced that only these lines are required:
Put them in your
functions.php
file and you're set.我通过结合 Donal MacArthur 的稍微修改过的 parse_shortcode_content 函数(他最初手动调用 wpautop...我已将其删除)来尽可能地解决了这个问题。通过重新排序默认过滤器以稍后运行 wpautop...之后短代码已经被处理而不是之前的,
并且移动过滤器
编辑:
不再需要
parse_shortcode_content()
函数(如果曾经需要)。 。I solved this as best as possible by combining a slightly modified parse_shortcode_content function from Donal MacArthur (his originally manually calls wpautop... which I've removed. With the re-ordering of default filters to run wpautop much later... after the shortcode has already been processed instead of before.
and moving the filters
EDIT:
The
parse_shortcode_content()
function is no longer required (if it ever was). Simply adjust the filter order.就我而言 - 这个解决方案破坏了侧面短代码之一(revslider)。
所以我在这里找到了另一个解决方案:
http://wordpress-hackers.1065353.n5.nabble。 com/shortcode-unautop-tp42085p42086.html
这是使用另一个像这样的过滤器:
它对我来说效果很好:)
In my case - this solution has broken one of the side shortcodes (revslider).
So I've found another solution here:
http://wordpress-hackers.1065353.n5.nabble.com/shortcode-unautop-tp42085p42086.html
Which is to use another filter like this:
It works fine for me :)
请在此处查看我的答案:
从短代码内容中删除 wpautop/删除缓冲中的空格
它允许您使用以下命令关闭任意数量的特定短代码的 wpautop:
Please see my answer here:
Remove wpautop from shortcode content / remove whitespace in buffering
It allows you to turn off wpautop for as many specific shortcodes as you want using this: