I am trying to make a WordPress theme, following the Wordpress Coding Standards - WPCS. In functions.php, I have a function to get only the teaser (text above the read more-tag). The function works, however I get an error from Code Sniffer that Overriding WordPress globals is prohibited

Any suggestions on how to achieve this, while following the Coding Standards would be great!

My code:

global $more;
$more_saved = $more;

// Sets $more to not showing the content after the more tag.
$more = 0;
echo esc_html( get_the_content( '', false ) );

// Restores $more.
$more = $more_saved;

1 Answer 1


get_extended() saved me! The returned array has 'main' and 'extended' keys. Main has the text before the <!--more-->. The 'extended' key has the content after the <!--more--> comment.

$content = get_post_field( 'post_content', get_the_ID() );
$content_parts = get_extended( $content );
echo esc_html( strip_tags( $content_parts['main'] ) );

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.