我有一个由 WordPress 驱动的网站,其主页上使用静态页面,仅使用短代码来生成内容。
页面通过将首页设置为静态页面并使用 the_content() 来获取这些短代码;在 page.php 上。页面内容没有空格,只有短代码,所以看起来像这样:
[content-shortcode blah blah][more content-shortcode blah blah]
一切正常,除了 WordPress 添加了一个空的<p></p>
在短代码之前和所有短代码代码末尾的另一个 P /P (短代码之间没有任何内容)。
我怎样才能删除它们?不过,我不想禁用全局 wpautop 删除功能,因为它对某些用户可能有用,我只想删除主页上出现的第一个和最后一个 P。
您可以尝试一些方法。
您可以推迟wp_autop
因为它在短代码输出之前处理:
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12);
或者使用cleanup_shortcode_fix()应该有助于解决您的问题的功能:
function cleanup_shortcode_fix($content) {
$array = array('<p>[' => '[', ']</p>' => ']', ']<br />' => ']', ']<br>' => ']');
$content = strtr($content, $array);
return $content;
}
add_filter('the_content', 'cleanup_shortcode_fix');
$string = preg_replace_('/<p>s*</p>/', '', $string);
add_filter('the_content', 'cleanup_shortcode_fix', 1);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)