read more button even if there is no Excerpt

  • Tangerine85

    #24712

    Hi there

    I used this code from a similar entry, and it worked better cause now I don’t get two buttons for the posts that do have content.

    The only problem is that it messes up the excerpt, it erases some letters.

    Something about the graphene_trim_all_excerpt($text) function … I think

    function graphene_excerpt_more($more) {
    global $post;
    return '… <a>ID) . '">» Read More</a>';
    }
    add_filter('excerpt_more', 'graphene_excerpt_more');

    function graphene_new_excerpt_length($length) {
    return 120; // Here you can control the length of your excerpt (word count)
    }
    add_filter('excerpt_length', 'graphene_new_excerpt_length');

    function graphene_trim_all_excerpt($text) {
    // Creates an excerpt if needed; and shortens the manual excerpt as well
    global $post;
    if ( empty($text) ) {
    $text = get_the_content('');
    }
    $text = strip_shortcodes( $text ); // optional
    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]>', $text);

    $text = strip_tags($text);
    $excerpt_length = apply_filters('excerpt_length', 55);
    $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    $words = preg_split("/[nrt ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
    if (count($words)> $excerpt_length) {
    array_pop($words);
    $text = implode(' ', $words);
    } else {
    $text = implode(' ', $words);
    }
    $text = $text . $excerpt_more;
    return $text;
    }

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'graphene_trim_all_excerpt');

    Thanks so much for your help

    Tangerine85

    #24713

    Nevermind!

    I fixed this line

    $words = preg_split("/[nrt ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);

    Thank you for your help!

Viewing 2 posts - 11 through 12 (of 12 total)

  • 1
  • 2
  • You must be logged in to reply to this topic.