With the default WordPress Excerpt function. WordPress strips the header tags (e.g. h1 tag) but keeps the unformatted text, that lies within the opening/closing of the h1 tag, displayed as part of the excerpt.
Is there a way, in addition of striping the h1 tag to also completely remove the text within the tag, when displaying the excerpt?
Thanks.
Rather than messing with regex, you might consider using a user-defined excerpt (i.e. a manual excerpt, which retains HTML tags, rather than relying solely on the automatic excerpt, which strips HTML tags.
Depending on your specific use case, using the manual excerpt for displaying HTML-formatted excerpts is usually an easier approach.
Here is a function that works for me.
It should be noted that regexing HTML is not the best solution, but I think it’s the most practical for something simple such as this.
Thanks @m0r7if3r for all your help. I don’t think I would have figured out the Regex part.
This is the code I am using and it works: