Search results – Remove <h1>
-
Hey all
I’ve got a search results page on which I’m outputting the title of the post/page with an excerpt below.
At present I’m using this function to trim the_excerpt down to 250 characters and follow with a ‘…’ :
<?php $little_excerpt = trim(substr(strip_tags(get_the_excerpt()),0,250))."..."; ?> <?php echo $little_excerpt; ?>
This works, even if there is no excerpt specified for the post (WP generates it automatically am I right?)
The problem I’m having is that all my post content entries start with <h1>Page title</h1> so when my excerpt is output I get something like this:
Expertise In Action Our flexible, professional training has produced great results for diverse organisations
Because my post content looks like this
<h1>Expertise In Action</h1><p>Our flexible, professional training has produced great results for diverse organisations</p>
As the h1 and page title are the same in most cases what I’m trying to do is strip out the <h1> and output everything past this i.e.
Our flexible, professional training has produced great results for diverse organisations
I’ve tried using PHP preg_replace such as this
<?php $little_excerpt = trim(substr(strip_tags(preg_replace("<h1>.*?<\/h1>","",get_the_excerpt())),0,200))."..."; ?>
But I get an Unknown modifier ‘.’ error.
Can anyone provide me with a function which can achieve what I’m after?
Thanks in advance
Matt
- The topic ‘Search results – Remove <h1>’ is closed to new replies.