简码中禁用自动格式化

简码中禁用自动格式化

本文介绍了在 WordPress 简码中禁用自动格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过有关创建(原始)短代码的教程,其中的代码保持不变,

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

但不幸的是,这一次只适用于一个短代码...因为 else 语句绕过普通过滤器并调用函数方向.我对 autop 和 texturize 函数的其他修改被忽略了.

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.

有没有办法 1. 匹配多个短代码和 2. 将我的其他添加/删除过滤器保留到 the_content?

Is there a way to 1. match multiple shortcodes and 2. preserve my other add/remove filters to the_content?

推荐答案

在多个网站上实施@helgatheviking 的解决方案后,我确信只有这些行是必需的:

After implementing @helgatheviking's solution on multiple websites, I'm convinced that only these lines are required:

// Move wpautop filter to AFTER shortcode is processed
remove_filter('the_content', 'wpautop');
add_filter('the_content', 'wpautop', 99);
add_filter('the_content', 'shortcode_unautop', 100);

把它们放在你的 functions.php 文件中,你就设置好了.

Put them in your functions.php file and you're set.

这篇关于在 WordPress 简码中禁用自动格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:44