禁止 WordPress 短代码中自动格式化

知更鸟 WordPress评论132阅读模式

用于去掉短代码中多余的p标签等。

方法一:文章源自知更鸟-https://zmingcx.com/disable-automatic-formatting-inside-wordpress-shortcodes.html

remove_filter('the_content', 'wpautop');
add_filter('the_content', 'wpautop', 99);
add_filter('the_content', 'shortcode_unautop', 100);

方法二:文章源自知更鸟-https://zmingcx.com/disable-automatic-formatting-inside-wordpress-shortcodes.html

if( !function_exists('zm_fix_shortcodes') ) {
	function zm_fix_shortcodes($content){   
		$array = array (
			'<p>[' => '[', 
			']</p>' => ']', 
			']<br />' => ']'
		);
		$content = strtr($content, $array);
		return $content;
	}
	add_filter('the_content', 'zm_fix_shortcodes');
}

 文章源自知更鸟-https://zmingcx.com/disable-automatic-formatting-inside-wordpress-shortcodes.html 文章源自知更鸟-https://zmingcx.com/disable-automatic-formatting-inside-wordpress-shortcodes.html

weinxin
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定