2

Is there a known way to show the very first sentence of the content of a blog post? I know I can use the_excerpt(); but client has a strange requirement to show only the first sentence. If there is a known method for this that would be great to know. I appreciate it.

3
  • Did you try this? wordpress.stackexchange.com/questions/108826/…
    – Howard E
    Commented May 3, 2016 at 14:40
  • i read that and tried it. for one it doesn't work for me; for two i want this to be first sentence of the content and not excerpt. if i am forcing user to type in an excerpt that they would just type in the first sentence and i wouldn't need all of this.
    – Zach Smith
    Commented May 3, 2016 at 14:52
  • What exact part do you have issue with? Retrieving content? Cutting down to a first sentence?
    – Rarst
    Commented May 3, 2016 at 15:17

1 Answer 1

1

Assuming you want to cut off a string after the first full stop you could use something like this:

$the-content = "This is the first sentence. And this is the second";
$cut-in-two = explode('.', $the-content, 2);
$first-sentence = $cut-in-two[0];
2
  • curious how this would work with a dynamic the_content();
    – Zach Smith
    Commented May 3, 2016 at 22:49
  • @HollerTrain. Do you mean you're manipulating the result of the_content() with javascript on the user end? Then it won't work, obviously. However, if you're building a page on the server end with php, get_the_content() gives a string that can be manipulated as shown. You'd have to replace the first line with $the-content = get_the_content();
    – cjbj
    Commented May 4, 2016 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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