0

I want to find a way for excerpt function to display exactly what i want inside a single post. the excerpt itself has starting and ending point as parameters to go and fetch the data. but what if i want to use words instead of them.

default:

$theExcerpt = get_the_content();
echo substr($theExcerpt,0,200);

I want this:

$theExcerpt = get_the_content();
echo substr($theExcerpt,'begining of paragraph', 'end of paragraph');

1

I think this is more a PHP than a WP question. Try using a regular expression with preg_match:

$theExcerpt = get_the_content();
$returnValue = preg_match('/(string01)(.*)(string02)/', $theExcerpt); 
echo $returnValue[0];

You have to replace string01 and string02 with your 'begining of paragraph' and 'end of paragraph'. There might be a more elegant way of using preg_match, but I think this will do the trick.

Don't forget to escape the output

| improve this answer | |
  • Thanks bro, this really helped – Ashur Jan 11 at 11:09

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.