get_extended() WordPress Function

The get_extended() function in WordPress is used to retrieve the full content of a post, including any extended content that may have been added via the "More" tag. This function is typically used when rendering a post in the "single" post template, and can be used to split the content into the main content and the extended content.

get_extended( string $post ) #

Get extended entry info (<!--more-->).


Description

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.

The returned array has ‘main’, ‘extended’, and ‘more_text’ keys. Main has the text before the <!--more-->. The ‘extended’ key has the content after the <!--more--> comment. The ‘more_text’ key has the custom "Read More" text.


Top ↑

Parameters

$post

(string)(Required)Post content.


Top ↑

Return

(string[]) Extended entry info.

  • 'main'
    (string) Content before the more tag.
  • 'extended'
    (string) Content after the more tag.
  • 'more_text'
    (string) Custom read more text, or empty string.


Top ↑

Source

File: wp-includes/post.php

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,
	);
}


Top ↑

Changelog

Changelog
VersionDescription
1.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More