Skip to content

Instantly share code, notes, and snippets.

@wordpressvn
Forked from vielhuber/index.php
Created October 27, 2022 08:38
Show Gist options
  • Select an option

  • Save wordpressvn/a9498d7fedb7289882d7a2c27adf4853 to your computer and use it in GitHub Desktop.

Select an option

Save wordpressvn/a9498d7fedb7289882d7a2c27adf4853 to your computer and use it in GitHub Desktop.

Revisions

  1. @vielhuber vielhuber revised this gist Mar 27, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.php
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ function wp_split_more($content, $type, $more_html = null)
    // remove gutenberg tags
    foreach (['before', 'after'] as $g1__value) {
    foreach (['/', ''] as $g2__value) {
    foreach (['wp:paragraph', 'wp:more', 'wp:html'] as $g3__value) {
    foreach (['wp:paragraph', 'wp:more', 'wp:html', 'wp:tadv/classic-paragraph'] as $g3__value) {
    $return[$g1__value] = str_replace(
    '<!-- ' . $g2__value . '' . $g3__value . ' -->',
    '',
  2. @vielhuber vielhuber revised this gist May 12, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -63,6 +63,9 @@ function wp_split_more($content, $type, $more_html = null)

    // add opening / closing p-tags
    foreach ($return as $return__key => $return__value) {
    if ($return[$return__key] == '') {
    continue;
    }
    $return[$return__key] =
    (mb_strpos($return[$return__key], '<p') !== 0 ? '<p>' : '') .
    $return[$return__key] .
  3. @vielhuber vielhuber revised this gist May 12, 2020. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -80,9 +80,8 @@ function wp_split_more($content, $type, $more_html = null)
    echo wp_split_more(get_post_field('post_content', get_the_ID()), 'before', '<a href="'.get_permalink(get_the_ID()).'" class="more">&gt;&gt;&gt;</a>');
    echo '</div>';
    if( wp_split_more(get_post_field('post_content', get_the_ID()), 'after') !== null && wp_split_more(get_post_field('post_content', get_the_ID()), 'after') != "" ) {
    echo '<div class="after">';
    echo wp_split_more(get_post_field('post_content', get_the_ID()), 'after');
    echo '</div>';
    echo '</div>';
    }
    ?>
    echo '<div class="after">';
    echo wp_split_more(get_post_field('post_content', get_the_ID()), 'after');
    echo '</div>';
    }
    echo '</div>';
  4. @vielhuber vielhuber revised this gist May 12, 2020. 1 changed file with 30 additions and 25 deletions.
    55 changes: 30 additions & 25 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -22,33 +22,37 @@ function wp_split_more($content, $type, $more_html = null)

    // clean up
    // remove gutenberg tags
    $return['before'] = str_replace('<!-- wp:paragraph -->', '', $return['before']);
    $return['before'] = str_replace('<!-- /wp:paragraph -->', '', $return['before']);
    $return['before'] = str_replace('<!-- wp:more -->', '', $return['before']);
    $return['after'] = str_replace('<!-- /wp:more -->', '', $return['after']);
    $return['after'] = str_replace('<!-- wp:paragraph -->', '', $return['after']);
    $return['after'] = str_replace('<!-- /wp:paragraph -->', '', $return['after']);
    foreach (['before', 'after'] as $g1__value) {
    foreach (['/', ''] as $g2__value) {
    foreach (['wp:paragraph', 'wp:more', 'wp:html'] as $g3__value) {
    $return[$g1__value] = str_replace(
    '<!-- ' . $g2__value . '' . $g3__value . ' -->',
    '',
    $return[$g1__value]
    );
    }
    }
    }

    foreach ($return as $return__key => $return__value) {
    // remove whitespace
    $return[$return__key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$return__key]));
    // remove falsly opening p tag
    if (strpos($return[$return__key], '</p>') === 0) {
    $return[$return__key] = trim(substr($return[$return__key], strlen('</p>')));
    // remove all opening tags
    foreach (['<p></p>', '<p>', '</p>'] as $tags__value) {
    if (mb_strpos($return[$return__key], $tags__value) === 0) {
    $return[$return__key] = trim(mb_substr($return[$return__key], mb_strlen($tags__value)));
    }
    }
    // remove opening p tag
    if (strpos($return[$return__key], '<p>') === 0) {
    $return[$return__key] = trim(substr($return[$return__key], strlen('<p>')));
    }
    // remove closing p tag
    if (strrpos($return[$return__key], '<p>') === strlen($return[$return__key]) - strlen('<p>')) {
    $return[$return__key] = trim(
    substr($return[$return__key], 0, strlen($return[$return__key]) - strlen('<p>'))
    );
    }
    if (strrpos($return[$return__key], '</p>') === strlen($return[$return__key]) - strlen('</p>')) {
    $return[$return__key] = trim(
    substr($return[$return__key], 0, strlen($return[$return__key]) - strlen('</p>'))
    );
    // remove all closing tags
    foreach (['<p></p>', '<p>', '</p>'] as $tags__value) {
    if (
    mb_strrpos($return[$return__key], $tags__value) ===
    mb_strlen($return[$return__key]) - mb_strlen($tags__value)
    ) {
    $return[$return__key] = trim(
    mb_substr($return[$return__key], 0, mb_strlen($return[$return__key]) - mb_strlen($tags__value))
    );
    }
    }
    }

    @@ -60,12 +64,13 @@ function wp_split_more($content, $type, $more_html = null)
    // add opening / closing p-tags
    foreach ($return as $return__key => $return__value) {
    $return[$return__key] =
    (strpos($return[$return__key], '<p>') !== 0 ? '<p>' : '') .
    (mb_strpos($return[$return__key], '<p') !== 0 ? '<p>' : '') .
    $return[$return__key] .
    (strrpos($return[$return__key], '</p>') !== strlen($return[$return__key]) - mb_strlen('</p>')
    (mb_strrpos($return[$return__key], '</p>') !== mb_strlen($return[$return__key]) - mb_strlen('</p>')
    ? '</p>'
    : '');
    }

    return $return[$type];
    }

  5. @vielhuber vielhuber revised this gist Mar 27, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,8 @@ function wp_split_more($content, $type, $more_html = null)
    $return['before'] = str_replace('<!-- /wp:paragraph -->', '', $return['before']);
    $return['before'] = str_replace('<!-- wp:more -->', '', $return['before']);
    $return['after'] = str_replace('<!-- /wp:more -->', '', $return['after']);
    $return['after'] = str_replace('<!-- wp:paragraph -->', '', $return['after']);
    $return['after'] = str_replace('<!-- /wp:paragraph -->', '', $return['after']);
    foreach ($return as $return__key => $return__value) {
    // remove whitespace
    $return[$return__key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$return__key]));
  6. @vielhuber vielhuber revised this gist Feb 20, 2020. 1 changed file with 36 additions and 20 deletions.
    56 changes: 36 additions & 20 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -5,50 +5,66 @@


    // with own function (wordpress own function has problems with enabled p tags)
    function wp_split_more($content, $type, $more_html = null) {

    function wp_split_more($content, $type, $more_html = null)
    {
    $return = [
    'before' => null,
    'after' => null
    ];

    // split up
    if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    if (preg_match('/<!--more(.*?)?-->/', $content, $matches)) {
    list($return['before'], $return['after']) = explode($matches[0], $content, 2);
    }
    else {
    } else {
    $return['before'] = $content;
    $return['after'] = '';
    }

    // clean up
    // remove gutenberg tags
    $return['before'] = str_replace('<!-- wp:paragraph -->','',$return['before']);
    $return['before'] = str_replace('<!-- /wp:paragraph -->','',$return['before']);
    $return['before'] = str_replace('<!-- wp:more -->','',$return['before']);
    $return['after'] = str_replace('<!-- /wp:more -->','',$return['after']);
    foreach($return as $key=>$value) {
    $return['before'] = str_replace('<!-- wp:paragraph -->', '', $return['before']);
    $return['before'] = str_replace('<!-- /wp:paragraph -->', '', $return['before']);
    $return['before'] = str_replace('<!-- wp:more -->', '', $return['before']);
    $return['after'] = str_replace('<!-- /wp:more -->', '', $return['after']);
    foreach ($return as $return__key => $return__value) {
    // remove whitespace
    $return[$key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$key]));
    $return[$return__key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$return__key]));
    // remove falsly opening p tag
    if( strpos($return[$key], '</p>') === 0 ) { $return[$key] = trim(substr($return[$key], strlen('</p>'))); }
    if (strpos($return[$return__key], '</p>') === 0) {
    $return[$return__key] = trim(substr($return[$return__key], strlen('</p>')));
    }
    // remove opening p tag
    if( strpos($return[$key], '<p>') === 0 ) { $return[$key] = trim(substr($return[$key], strlen('<p>'))); }
    if (strpos($return[$return__key], '<p>') === 0) {
    $return[$return__key] = trim(substr($return[$return__key], strlen('<p>')));
    }
    // remove closing p tag
    if( strrpos($return[$key], '<p>') === strlen($return[$key])-strlen('<p>') ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen('<p>'))); }
    if( strrpos($return[$key], '</p>') === strlen($return[$key])-strlen('</p>') ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen('</p>'))); }
    if (strrpos($return[$return__key], '<p>') === strlen($return[$return__key]) - strlen('<p>')) {
    $return[$return__key] = trim(
    substr($return[$return__key], 0, strlen($return[$return__key]) - strlen('<p>'))
    );
    }
    if (strrpos($return[$return__key], '</p>') === strlen($return[$return__key]) - strlen('</p>')) {
    $return[$return__key] = trim(
    substr($return[$return__key], 0, strlen($return[$return__key]) - strlen('</p>'))
    );
    }
    }

    // add more tag
    if( $more_html !== null && $return['after'] !== '' ) {
    $return['before'] = $return['before'].''.$more_html;
    if ($more_html !== null && $return['after'] !== '') {
    $return['before'] = $return['before'] . '' . $more_html;
    }

    // add opening / closing p-tags
    $return['before'] = (($return['before'][0] != '<')?('<p>'):('')).$return['before'].(($return['before'][strlen($return['before'])-1] != '>')?('</p>'):(''));
    $return['after'] = (($return['after'][0] != '<')?('<p>'):('')).$return['after'].(($return['after'][strlen($return['after'])-1] != '>')?('</p>'):(''));
    foreach ($return as $return__key => $return__value) {
    $return[$return__key] =
    (strpos($return[$return__key], '<p>') !== 0 ? '<p>' : '') .
    $return[$return__key] .
    (strrpos($return[$return__key], '</p>') !== strlen($return[$return__key]) - mb_strlen('</p>')
    ? '</p>'
    : '');
    }
    return $return[$type];

    }

    // example usage
  7. @vielhuber vielhuber revised this gist Aug 20, 2018. 1 changed file with 16 additions and 11 deletions.
    27 changes: 16 additions & 11 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -8,35 +8,40 @@
    function wp_split_more($content, $type, $more_html = null) {

    $return = [
    "before" => null,
    "after" => null
    'before' => null,
    'after' => null
    ];

    // split up
    if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    list($return["before"], $return["after"]) = explode($matches[0], $content, 2);
    list($return['before'], $return['after']) = explode($matches[0], $content, 2);
    }
    else {
    $return["before"] = $content;
    $return["after"] = '';
    $return['before'] = $content;
    $return['after'] = '';
    }

    // clean up
    // remove gutenberg tags
    $return['before'] = str_replace('<!-- wp:paragraph -->','',$return['before']);
    $return['before'] = str_replace('<!-- /wp:paragraph -->','',$return['before']);
    $return['before'] = str_replace('<!-- wp:more -->','',$return['before']);
    $return['after'] = str_replace('<!-- /wp:more -->','',$return['after']);
    foreach($return as $key=>$value) {
    // remove whitespace
    $return[$key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$key]));
    // remove falsly opening p tag
    if( strpos($return[$key], "</p>") === 0 ) { $return[$key] = trim(substr($return[$key], strlen("</p>"))); }
    if( strpos($return[$key], '</p>') === 0 ) { $return[$key] = trim(substr($return[$key], strlen('</p>'))); }
    // remove opening p tag
    if( strpos($return[$key], "<p>") === 0 ) { $return[$key] = trim(substr($return[$key], strlen("<p>"))); }
    if( strpos($return[$key], '<p>') === 0 ) { $return[$key] = trim(substr($return[$key], strlen('<p>'))); }
    // remove closing p tag
    if( strrpos($return[$key], "<p>") === strlen($return[$key])-strlen("<p>") ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen("<p>"))); }
    if( strrpos($return[$key], "</p>") === strlen($return[$key])-strlen("</p>") ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen("</p>"))); }
    if( strrpos($return[$key], '<p>') === strlen($return[$key])-strlen('<p>') ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen('<p>'))); }
    if( strrpos($return[$key], '</p>') === strlen($return[$key])-strlen('</p>') ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen('</p>'))); }
    }

    // add more tag
    if( $more_html !== null && $return["after"] !== "" ) {
    $return["before"] = $return["before"]."".$more_html;
    if( $more_html !== null && $return['after'] !== '' ) {
    $return['before'] = $return['before'].''.$more_html;
    }

    // add opening / closing p-tags
  8. @vielhuber vielhuber revised this gist May 14, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -40,8 +40,8 @@ function wp_split_more($content, $type, $more_html = null) {
    }

    // add opening / closing p-tags
    $return["before"] = "<p>".$return["before"]."</p>";
    $return["after"] = "<p>".$return["after"]."</p>";
    $return['before'] = (($return['before'][0] != '<')?('<p>'):('')).$return['before'].(($return['before'][strlen($return['before'])-1] != '>')?('</p>'):(''));
    $return['after'] = (($return['after'][0] != '<')?('<p>'):('')).$return['after'].(($return['after'][strlen($return['after'])-1] != '>')?('</p>'):(''));
    return $return[$type];

    }
  9. @vielhuber vielhuber revised this gist Dec 10, 2016. No changes.
  10. @vielhuber vielhuber revised this gist Aug 28, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -49,11 +49,11 @@ function wp_split_more($content, $type, $more_html = null) {
    // example usage
    echo '<div class="content">';
    echo '<div class="before">';
    echo wp_split_more($p->post_content, 'before', '<a href="'.get_permalink($p->post_id).'" class="more">&gt;&gt;&gt;</a>');
    echo wp_split_more(get_post_field('post_content', get_the_ID()), 'before', '<a href="'.get_permalink(get_the_ID()).'" class="more">&gt;&gt;&gt;</a>');
    echo '</div>';
    if( wp_split_more($p->post_content, 'after') !== null && wp_split_more($p->post_content, 'after') != "" ) {
    if( wp_split_more(get_post_field('post_content', get_the_ID()), 'after') !== null && wp_split_more(get_post_field('post_content', get_the_ID()), 'after') != "" ) {
    echo '<div class="after">';
    echo wp_split_more($p->post_content, 'after');
    echo wp_split_more(get_post_field('post_content', get_the_ID()), 'after');
    echo '</div>';
    echo '</div>';
    }
  11. @vielhuber vielhuber revised this gist Jun 25, 2016. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -24,19 +24,19 @@ function wp_split_more($content, $type, $more_html = null) {
    // clean up
    foreach($return as $key=>$value) {
    // remove whitespace
    $return[$key] = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$key]);
    $return[$key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$key]));
    // remove falsly opening p tag
    if( strpos($return[$key], "</p>") === 0 ) { $return[$key] = substr($return[$key], strlen("</p>")); }
    if( strpos($return[$key], "</p>") === 0 ) { $return[$key] = trim(substr($return[$key], strlen("</p>"))); }
    // remove opening p tag
    if( strpos($return[$key], "<p>") === 0 ) { $return[$key] = substr($return[$key], strlen("<p>")); }
    // remove falsly closing p tag
    if( strrpos($return[$key], "<p>") === strlen($return[$key])-strlen("<p>") ) { $return[$key] = substr($return[$key], 0, strlen($return[$key])-strlen("<p>")); }
    if( strrpos($return[$key], "</p>") === strlen($return[$key])-strlen("</p>") ) { $return[$key] = substr($return[$key], 0, strlen($return[$key])-strlen("</p>")); }
    if( strpos($return[$key], "<p>") === 0 ) { $return[$key] = trim(substr($return[$key], strlen("<p>"))); }
    // remove closing p tag
    if( strrpos($return[$key], "<p>") === strlen($return[$key])-strlen("<p>") ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen("<p>"))); }
    if( strrpos($return[$key], "</p>") === strlen($return[$key])-strlen("</p>") ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen("</p>"))); }
    }

    // add more tag
    if( $more_html !== null && $return["after"] !== "" ) {
    $return["before"] = $return["before"]." ".$more_html;
    $return["before"] = $return["before"]."".$more_html;
    }

    // add opening / closing p-tags
  12. @vielhuber vielhuber revised this gist Jun 25, 2016. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,8 @@ function wp_split_more($content, $type, $more_html = null) {
    if( strpos($return[$key], "</p>") === 0 ) { $return[$key] = substr($return[$key], strlen("</p>")); }
    // remove opening p tag
    if( strpos($return[$key], "<p>") === 0 ) { $return[$key] = substr($return[$key], strlen("<p>")); }
    // remove closing p tag
    // remove falsly closing p tag
    if( strrpos($return[$key], "<p>") === strlen($return[$key])-strlen("<p>") ) { $return[$key] = substr($return[$key], 0, strlen($return[$key])-strlen("<p>")); }
    if( strrpos($return[$key], "</p>") === strlen($return[$key])-strlen("</p>") ) { $return[$key] = substr($return[$key], 0, strlen($return[$key])-strlen("</p>")); }
    }

    @@ -48,7 +49,7 @@ function wp_split_more($content, $type, $more_html = null) {
    // example usage
    echo '<div class="content">';
    echo '<div class="before">';
    echo wp_split_more($p->post_content, 'before', '<a href="#" class="more">&gt;&gt;&gt;</a>');
    echo wp_split_more($p->post_content, 'before', '<a href="'.get_permalink($p->post_id).'" class="more">&gt;&gt;&gt;</a>');
    echo '</div>';
    if( wp_split_more($p->post_content, 'after') !== null && wp_split_more($p->post_content, 'after') != "" ) {
    echo '<div class="after">';
  13. @vielhuber vielhuber revised this gist Jun 20, 2016. 1 changed file with 50 additions and 24 deletions.
    74 changes: 50 additions & 24 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -5,29 +5,55 @@


    // with own function (wordpress own function has problems with enabled p tags)
    function wp_split_more($content) {

    // split up
    if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    list($before, $after) = explode($matches[0], $content, 2);
    $more_text = $matches[1];
    }
    else {
    $before = $content;
    $after = '';
    $more_text = '';
    }

    // remove whitespace
    $before = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $before);
    $after = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $after);
    $more_text = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $more_text);

    return [
    'before' => $before,
    'after' => $after,
    'more_text' => $more_text
    ];

    function wp_split_more($content, $type, $more_html = null) {

    $return = [
    "before" => null,
    "after" => null
    ];

    // split up
    if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    list($return["before"], $return["after"]) = explode($matches[0], $content, 2);
    }
    else {
    $return["before"] = $content;
    $return["after"] = '';
    }

    // clean up
    foreach($return as $key=>$value) {
    // remove whitespace
    $return[$key] = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$key]);
    // remove falsly opening p tag
    if( strpos($return[$key], "</p>") === 0 ) { $return[$key] = substr($return[$key], strlen("</p>")); }
    // remove opening p tag
    if( strpos($return[$key], "<p>") === 0 ) { $return[$key] = substr($return[$key], strlen("<p>")); }
    // remove closing p tag
    if( strrpos($return[$key], "</p>") === strlen($return[$key])-strlen("</p>") ) { $return[$key] = substr($return[$key], 0, strlen($return[$key])-strlen("</p>")); }
    }

    // add more tag
    if( $more_html !== null && $return["after"] !== "" ) {
    $return["before"] = $return["before"]." ".$more_html;
    }

    // add opening / closing p-tags
    $return["before"] = "<p>".$return["before"]."</p>";
    $return["after"] = "<p>".$return["after"]."</p>";
    return $return[$type];

    }

    // example usage
    echo '<div class="content">';
    echo '<div class="before">';
    echo wp_split_more($p->post_content, 'before', '<a href="#" class="more">&gt;&gt;&gt;</a>');
    echo '</div>';
    if( wp_split_more($p->post_content, 'after') !== null && wp_split_more($p->post_content, 'after') != "" ) {
    echo '<div class="after">';
    echo wp_split_more($p->post_content, 'after');
    echo '</div>';
    echo '</div>';
    }
    ?>
  14. @vielhuber vielhuber revised this gist Jun 20, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.php
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@


    // with own function (wordpress own function has problems with enabled p tags)
    function wp_split_content($content) {
    function wp_split_more($content) {

    // split up
    if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
  15. @vielhuber vielhuber revised this gist Jun 20, 2016. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,15 @@
    echo get_extended($p->post_content)['extended'];


    // outside of wordpress with own function
    // with own function (wordpress own function has problems with enabled p tags)
    function wp_split_content($content) {

    // split up
    if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    list($before, $after) = explode($matches[0], $content, 2);
    $more_text = $matches[1];
    } else {
    }
    else {
    $before = $content;
    $after = '';
    $more_text = '';
  16. @vielhuber vielhuber revised this gist Jun 20, 2016. No changes.
  17. @vielhuber vielhuber revised this gist May 24, 2016. 1 changed file with 28 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,32 @@
    <?php
    // with wordpress native functions
    echo get_extended($p->post_content)['main'];
    echo get_extended($p->post_content)['extended'];


    // outside of wordpress with own function
    function wp_split_content($content) {

    // split up
    if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    list($before, $after) = explode($matches[0], $content, 2);
    $more_text = $matches[1];
    } else {
    $before = $content;
    $after = '';
    $more_text = '';
    }

    // remove whitespace
    $before = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $before);
    $after = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $after);
    $more_text = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $more_text);

    return [
    'before' => $before,
    'after' => $after,
    'more_text' => $more_text
    ];

    }
    ?>
  18. @vielhuber vielhuber renamed this gist Sep 9, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  19. @vielhuber vielhuber created this gist Sep 9, 2015.
    4 changes: 4 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    <?php
    echo get_extended($p->post_content)['main'];
    echo get_extended($p->post_content)['extended'];
    ?>