我有一个WordPress驱动的网站,在主页上使用一个静态页面,只有短代码来生成内容.
该页面通过将首页设置为静态页面并使用the_content()来获取这些短代码; 在page.php上.页面内容没有空格,只有短代码,所以看起来像这样:
[content-shortcode blah blah][more content-shortcode blah blah]
Run Code Online (Sandbox Code Playgroud)
一切正常,除了WordPress <p></p>在短代码前添加一个空,在所有短代码末尾添加另一个P/P(短代码之间没有任何内容).
我该如何删除它们?我不想禁用全局wpautop删除功能,因为它对某些用户有用,我只想删除主页上显示的第一个和最后一个P.
Sea*_*nWM 19
你可以尝试一些事情.
您可以推迟,wp_autop因为它在短代码输出之前处理:
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12);
Run Code Online (Sandbox Code Playgroud)
或者使用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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7443 次 |
| 最近记录: |