get_extended

The timeline below displays how wordpress function get_extended has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Gets extended entry info (<!--more-->).
 *
 * 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.
 *
 * @since 1.0.0
 *
 * @param string $post Post content.
 * @return string[] {
 *     Extended entry info.
 *
 *     @type string $main      Content before the more tag.
 *     @type string $extended  Content after the more tag.
 *     @type string $more_text Custom read more text, or empty string.
 * }
 */
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);
}

WordPress Version: 5.4

/**
 * Get extended entry info (<!--more-->).
 *
 * 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.
 *
 * @since 1.0.0
 *
 * @param string $post Post content.
 * @return string[] {
 *     Extended entry info.
 *
 *     @type string $main      Content before the more tag.
 *     @type string $extended  Content after the more tag.
 *     @type string $more_text Custom read more text, or empty string.
 * }
 */
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);
}

WordPress Version: 4.4

/**
 * Get extended entry info (<!--more-->).
 *
 * 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.
 *
 * @since 1.0.0
 *
 * @param string $post Post content.
 * @return array Post before ('main'), after ('extended'), and custom read more ('more_text').
 */
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);
}

WordPress Version: 4.1

/**
 * Get extended entry info (<!--more-->).
 *
 * 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.
 *
 * @since 1.0.0
 *
 * @param string $post Post content.
 * @return array Post before ('main'), after ('extended'), and custom readmore ('more_text').
 */
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);
}

WordPress Version: 4.0

/**
 * Get extended entry info (<!--more-->).
 *
 * 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 <code><!--more--></code>. The 'extended' key has the content after the
 * <code><!--more--></code> comment. The 'more_text' key has the custom "Read More" text.
 *
 * @since 1.0.0
 *
 * @param string $post Post content.
 * @return array Post before ('main'), after ('extended'), and custom readmore ('more_text').
 */
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);
}

WordPress Version: 3.7

/**
 * Get extended entry info (<!--more-->).
 *
 * 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 <code><!--more--></code>. The 'extended' key has the content after the
 * <code><!--more--></code> comment. The 'more_text' key has the custom "Read More" text.
 *
 * @since 1.0.0
 *
 * @param string $post Post content.
 * @return array Post before ('main'), after ('extended'), and custom readmore ('more_text').
 */
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);
}