我使用了WordPress过滤器,但我无法删除所有额外的<p></p>
标签。
这<p></p>
标签添加到页面和帖子内容的最后一部分。
但是我想删除WordPress帖子和页面视图中的所有<p></p>
标签
请使用这行代码而不是the_content();
/the_excerpt();
然后它会正常工作。
对于内容
<?php remove_filter( 'the_content', 'wpautop' ); the_content(); ?>
摘录
<?php remove_filter( 'the_excerpt', 'wpautop' ); the_content(); ?>
希望它会有所帮助。谢谢。
在 PHP 中,无论你在哪里发布echo get_the_content($params)
(也许只是内容.php,取决于主题),请执行以下操作:
echo preg_replace(array('<p>','</p>'),array('',''),get_the_content($params),1)
这将用空字符串''
替换任何出现的<p>
;同样对于</p>
。
这样做不管你是用HTML还是视觉模式创作内容,如果它在那里,它会删除它;如果没有,它不会破坏它。
如果你只是不喜欢任何有标签<p></p>
样式,那么从style.css发布p{}
,并描述你想要它的外观 - 例如,你想要更小还是更大的段落之间的间隙?
请尝试使用以下代码:
remove_filter( 'the_content', 'wpautop' );
OR
remove_filter( 'the_excerpt', 'wpautop' );
它将从内容中删除所有额外的<p>
标签。
谢谢!