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
Add a comment  | 

1 Answer 1

Reset to default 1

At 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