0

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.'....'; }  ?>
1

1 Answer 1

0

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.

2
  • In this way, do I have to fill the excerpt field or not?
    – stepiadm
    Feb 11 at 9:52
  • No. If the except field is not populated, an excerpt will be auto-generated from the post content.
    – vancoder
    Feb 11 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.