Wordpress 不断向简码和内容添加自动段落标签
Wordpress keeps adding auto paragraph tags to shortcodes and content
我似乎无法阻止 wordpress 自动将段落添加到我键入的每一行,包括短代码和我输入可视化编辑器的任何原始 HTML。我已经尝试使用插件 "Toggle wpautop" 和 "Raw html" 来尝试转换它,但是它从来没有用过。是因为我使用的是视觉作曲家吗?它只是将 p 标签包裹在任何东西周围。
问题不在于 Visual Composer,它的发生纯粹是因为 autop
filter on the_content
。有几种方法可以解决它,但恕我直言,内容过滤器是处理它的最佳方法。
如果您愿意编辑 functions.php,您可以过滤 the_content
挂钩,通过添加以下内容来删除 strtr
短代码周围的 <p>
标签:
add_filter('the_content', 'remove_unneeded_silly_p_tags_from_shortcodes');
function remove_unneeded_silly_p_tags_from_shortcodes($the_content){
$array = array (
'<p>[' => '[', //replace "<p>[" with "["
']</p>' => ']', //replace "]</p>" with "]"
']<br />' => ']' //replace "]<br />" with "]"
);
$the_content = strtr($the_content, $array); //replaces instances of the keys in the array with their values
return $the_content;
}
其他选择 (like removing autop from the_content) 往往会产生相当深远的影响,所以我倾向于避免这种情况。您也可以尝试从添加的特定段落标签中删除边距样式,但由于自动添加,可能很难定位该特定标签...
试试这个,在你的 functions.php
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
我修改了@Frits 的回答。这往往会修复显示在屏幕底部的 very-annoying Google Chrome Mobile "Simplified View" nag。
add_filter('the_content', 'remove_unneeded_silly_p_tags_from_shortcodes');
function remove_unneeded_silly_p_tags_from_shortcodes($the_content){
$array = array (
'<p>' => '',
'</p>' => '<br /><br />'
);
$the_content = strtr($the_content, $array); //replaces instances of the keys in the array with their values
return $the_content;
}
这有一个问题,它会删除您添加到段落标签的所有 CSS 样式。但是好处很明显:没有GoogleChrome移动nag!
我似乎无法阻止 wordpress 自动将段落添加到我键入的每一行,包括短代码和我输入可视化编辑器的任何原始 HTML。我已经尝试使用插件 "Toggle wpautop" 和 "Raw html" 来尝试转换它,但是它从来没有用过。是因为我使用的是视觉作曲家吗?它只是将 p 标签包裹在任何东西周围。
问题不在于 Visual Composer,它的发生纯粹是因为 autop
filter on the_content
。有几种方法可以解决它,但恕我直言,内容过滤器是处理它的最佳方法。
如果您愿意编辑 functions.php,您可以过滤 the_content
挂钩,通过添加以下内容来删除 strtr
短代码周围的 <p>
标签:
add_filter('the_content', 'remove_unneeded_silly_p_tags_from_shortcodes');
function remove_unneeded_silly_p_tags_from_shortcodes($the_content){
$array = array (
'<p>[' => '[', //replace "<p>[" with "["
']</p>' => ']', //replace "]</p>" with "]"
']<br />' => ']' //replace "]<br />" with "]"
);
$the_content = strtr($the_content, $array); //replaces instances of the keys in the array with their values
return $the_content;
}
其他选择 (like removing autop from the_content) 往往会产生相当深远的影响,所以我倾向于避免这种情况。您也可以尝试从添加的特定段落标签中删除边距样式,但由于自动添加,可能很难定位该特定标签...
试试这个,在你的 functions.php
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
我修改了@Frits 的回答。这往往会修复显示在屏幕底部的 very-annoying Google Chrome Mobile "Simplified View" nag。
add_filter('the_content', 'remove_unneeded_silly_p_tags_from_shortcodes');
function remove_unneeded_silly_p_tags_from_shortcodes($the_content){
$array = array (
'<p>' => '',
'</p>' => '<br /><br />'
);
$the_content = strtr($the_content, $array); //replaces instances of the keys in the array with their values
return $the_content;
}
这有一个问题,它会删除您添加到段落标签的所有 CSS 样式。但是好处很明显:没有GoogleChrome移动nag!