admin管理员组文章数量:1134248
I am Using the Following Code and want to remove HTML All Elements.
<?php $exerpttext = substr(get_post_field('post_content', $post->ID), 0, 300);
if (!empty($exerpttext)) { echo $exerpttext.'....'; } ?>
I am Using the Following Code and want to remove HTML All Elements.
<?php $exerpttext = substr(get_post_field('post_content', $post->ID), 0, 300);
if (!empty($exerpttext)) { echo $exerpttext.'....'; } ?>
Share
Improve this question
asked Feb 10, 2022 at 14:00
stepiadmstepiadm
13 bronze badges
1
- Have you tried developer.wordpress.org/reference/functions/wp_strip_all_tags – Minh Tri Commented Feb 10, 2022 at 14:06
1 Answer
Reset to default 1At first glance, this appears to be an XY Problem.
If you simply want to increase the length of the excerpt auto-generated from the post content, you can use the excerpt_length hook in functions.php.
function modify_excerpt_length( $length ) {
return 300;
}
add_filter( 'excerpt_length', 'modify_excerpt_length', 99 );
Then simply call the excerpt in your template:
the_excerpt()
This will automatically remove all tags.
本文标签: How to Remove HTML Elements from Post Excerpt
版权声明:本文标题:How to Remove HTML Elements from Post Excerpt? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736841606a1955124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论