Using WordPress ‘get_extended()’ PHP function

The get_extended() WordPress PHP function retrieves the extended entry information, specifically the content before and after the <!--more--> tag in a post.

Usage

To use the get_extended() function, provide the post content as an argument:

$content_arr = get_extended($post_content);

Parameters

  • $post (string) – Required. The post content to be parsed.

More information

See WordPress Developer Resources: get_extended()

Examples

Basic Usage

Get the content before and after the <!--more--> tag:

// Get the post
$post = get_post();

// Use get_extended() to retrieve content before and after <!--more-->
$content_arr = get_extended($post->post_content);

// Display the content before and after <!--more-->
echo $content_arr['main']; // Content before <!--more-->
echo $content_arr['extended']; // Content after <!--more-->

Display a Custom Read More Text

Change the text displayed after the <!--more--> tag:

// Get the post
$post = get_post();

// Use get_extended() to retrieve content before and after <!--more-->
$content_arr = get_extended($post->post_content);

// Display the content before and after <!--more-->
echo $content_arr['main']; // Content before <!--more-->
echo $content_arr['more_text']; // Custom "Read More" text

Display Excerpts from the Latest Posts

Show the latest posts on your WordPress blog, but only the content before the <!--more--> tag:

$myposts = get_posts(array('posts_per_page' => 5));
foreach ($myposts as $post) :
    setup_postdata($post);
    $content_arr = get_extended($post->post_content);
    ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <br>
        <?php echo $content_arr['main']; ?>
    </li>
<?php endforeach; ?>

Show the full content of a post, with a custom Read More link:

// Get the post
$post = get_post();

// Use get_extended() to retrieve content before and after <!--more-->
$content_arr = get_extended($post->post_content);

// Display the content and a custom Read More link
echo $content_arr['main']; // Content before <!--more-->
echo $content_arr['extended']; // Content after <!--more-->
echo '<a href="' . get_permalink($post->ID) . '">' . $content_arr['more_text'] . '</a>'; // Custom "Read More" link

Add a Custom Separator Between Main and Extended Content

Display the main and extended content with a custom separator:

// Get the post
$post = get_post();

// Use get_extended() to retrieve content before and after <!--more-->
$content_arr = get_extended($post->post_content);

// Display the content with a custom separator
echo $content_arr['main']; // Content before <!--more-->
echo ' [Custom Separator] ';
echo $content_arr['extended']; // Content after <!--more-->