Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • in reply to: Stop Stripping from Excerpts #1394
    Tanzytales
    Member

    Update. Formulated a sultion.. it’s not the most elegent but it works 99%..

    function improved_trim_excerpt($text) {
    global $post;
    if ( '' == $text ) {
    $text = get_the_content('');
    $text = strip_shortcodes( $text );
    $text = apply_filters('the_content', $text);
    $text = str_replace('\]\]\>', ']]>', $text);
    $text = strip_tags($text, '');
    $excerpt_length = 40;
    $words = explode(' ', $text, $excerpt_length + 1);
    $text = force_balance_tags( $text );
    if (count($words)> $excerpt_length) {
    array_pop($words);
    array_push($words, 'ID) . '>' . 'Continue Reading...' . '');
    $text = implode(' ', $words);
    $text = force_balance_tags( $text );
    }
    }
    return $text;
    }

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

    I’m basically just styling my own read more link on the spot here.

    The only problem I have with this is that tags may not close properlu due to the word limit leaving an open tag and breaking the continue reading link (possibly the rest of the page). This occured once but just changing the word limit bandaided the problem. Not the most ideal fix though.

    As you can see I tried using force_balance_tags but it didnt seem to work.

    I would also prefer to use simplecatch_excerpt_more in this function instead of adding this one in manually. Do you see any way for me to do that here?

    in reply to: Stop Stripping from Excerpts #1393
    Tanzytales
    Member

    Thise code is the default. Seems to ignore html tags.


    function wp_trim_excerpt($text = '') {
    $raw_excerpt = $text;
    if ( '' == $text ) {
    $text = get_the_content('');

    $text = strip_shortcodes( $text );

    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]>', $text);
    $excerpt_length = apply_filters('excerpt_length', 55);
    $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    }
    return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
    }

    This code allows other tags to be included in excerpts but I can’t figure out a way to make it work with simple catch’s excerpt_more…

    function improved_trim_excerpt($text) { // Fakes an excerpt if needed
    global $post;
    if ( '' == $text ) {
    $text = get_the_content('');
    $text = apply_filters('the_content', $text);
    $text = str_replace('\]\]\>', ']]>', $text);
    $text = strip_tags($text, '');
    $excerpt_length = 50;
    $words = explode(' ', $text, $excerpt_length + 1);
    if (count($words)> $excerpt_length) {
    array_pop($words);
    array_push($words, '[...]');
    $text = implode(' ', $words);
    }
    }
    return $text;
    }

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

    in reply to: Stop Stripping from Excerpts #1391
    Tanzytales
    Member

    Half solved this problem… got images and videos to show up but now there’s no continue reading link, heh.

    in reply to: Stop Stripping from Excerpts #1386
    Tanzytales
    Member

    There’s no way to prevent the theme from stripping other html tags from excerpts?

Viewing 4 posts - 1 through 4 (of 4 total)