get_extended()WP 1.0.0

Divides content into 2 parts: before <!--more--> and after it. Returns an array with the resulting parts.

There should not be any space after the second dash and before the word 'more'. There can be text or space(s) after the word 'more', but won't be referenced.

No Hooks.


String[]. Post before ('main'), after ('extended'), and custom read more ('more_text').

	[main]      => 'some text', // text before the `<!--more-->` comment.
	[extended]  => 'some text', // text after the `<!--more-->` comment.
	[more_text] => ''           // if more is specified as: <!‐‐more reed more…‐‐>,
								// then this value will contain "reed more…"


$parts = get_extended( $post_content );
$post_content(string) (required)
The content of the post, which contains <!--more--> comment and which you want to split.



#1 Display first part of last 5 posts

If you want to display the latest posts on the blog, but you need to display only part of the text before the <!--more--> tag, use this code:

	global $post;

	$myposts = get_posts( array( 'numberposts'=>5 ) );

	foreach( $myposts as $post ){
		setup_postdata( $post );  
		$parts = get_extended( $post->post_content ); ?>
		   <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
		   <?php echo apply_filters( 'the_content', $parts['main'] ); // part before more ?>   

#2 Display advertising immediately after the <!--more--> tag

Let's say we need to display an ad block after the <!--more-->, on a separate page (file single.php). To do this, replace the_content() with the following code:

global $post;
$content_parts = get_extended( $post->post_content );

echo apply_filters( 'the_content', $content_parts['main'] );

echo "advertising  code here";

echo apply_filters( 'the_content', $content_parts['extended'] );


Since 1.0.0 Introduced.

get_extended() code WP 6.5.2

function get_extended( $post ) {
	// Match the new style more links.
	if ( preg_match( '/<!--more(.*?)?-->/', $post, $matches ) ) {
		list($main, $extended) = explode( $matches[0], $post, 2 );
		$more_text             = $matches[1];
	} else {
		$main      = $post;
		$extended  = '';
		$more_text = '';

	// Leading and trailing whitespace.
	$main      = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $main );
	$extended  = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $extended );
	$more_text = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $more_text );

	return array(
		'main'      => $main,
		'extended'  => $extended,
		'more_text' => $more_text,