I need to determine if the current post has a “more” tag. I’m currently using
$pos=strpos($post->post_content, '<!--more-->');
Am I missing a built in method similar to has_excerpt()?
I need to determine if the current post has a “more” tag. I’m currently using
$pos=strpos($post->post_content, '<!--more-->');
Am I missing a built in method similar to has_excerpt()?
You must be logged in to post a comment.
Quite simply put: there is no built in function that does the same thing as your code above.
Bonus content: More tag tricks
Making a quick note of the codes we could use to show
the_content();
if the More tag exists, andthe_excerpt();
if it doesn’t.Code #1 (Recommended)
(Credit: MichaelH)
Code #2
(Credit: Michael) Basically does #1 the other way around.
Code #3
(Credit: helgatheviking) For use only in edge cases where you cannot use
strpos()
. Generallystrpos()
is more efficient thanpreg_match()
.Making it more conditional:
What does it do? If the page shown is home, archive or search results page, then show
the_content();
if the More tag exists,the_excerpt();
if it doesn’t, and simply showthe_excerpt();
on all other pages.I could not get any of the provided solution to work, however I found this to be working well for me, publishing it as an extra solution if anybody else had problems getting it working. Just testing if the content is them same with and without stripping the teaser.
For the ones searching for a more WP related answer, You can use this logic:
For this, you can blame the WP Core if it doesn’t work right. 🙂
Reference: https://developer.wordpress.org/reference/functions/get_extended/