• I’m looking for simple solution, most preferably filter, that would remove header tags(with it’s content) from blog excerpts.

    Yes, i know that there is option for custom excerpts in wordpress posts by default.
    Yes, i know that there are plugins for excerpt customization.

Viewing 1 replies (of 1 total)
  • AddWeb Solution

    (@addweb-solution-pvt-ltd)

    Please add below code in your function.php file and remove H1/H2/H3 tag in your excerpt.

    add_filter( 'the_excerpt', 'wpse49280_strip_header_tags', 1 );
    function wpse49280_strip_header_tags( $excerpt ) {
        // this is just an example, there is probably a better regex
    
      $search    = array('#(<h([1-6])[^>]*>)\s?(.*)?\s?(<\/h\2>)#'); 
      $string    = preg_replace($search, '', $excerpt);
      return $string;
        
    }

    Let me know incase of any further queries/concern regarding the same.

Viewing 1 replies (of 1 total)
  • The topic ‘Remove h1/h2/h3 from excerpt’ is closed to new replies.