我正面临一个开发wordpress主题的大问题。我想在<h2></h2>
中显示帖子内容但默认情况下,它显示在<p></p>
. post内容也有<br>
。我想保留这个<br>
,想去掉<p></p>
。我已经使用了这个remove_filter ('the_content', 'wpautop');
,但它也删除了<br>
。
请告诉我怎么做?
将此添加到functions.php文件中…
function my_wp_content_function($content) {
return strip_tags($content,"<br><h2>"); //add any tags here you want to preserve
}
add_filter('the_content', my_wp_content_function);
我们只是使用PHP的内置strip_tags()函数与WordPress的add_filter()来自定义格式化the_content(),告诉它删除所有的html标签,同时保留你想要的(br和h2)。Wpautop是有用的,但不是在您需要的情况。
您可以简单地使用<?php echo get_the_content(); ?>
, <?php echo get_the_excerpt(); ?>