• Hi,

    I modified the functions.php file to limit the length of content on the blog homepage but the text is all running together, it’s completely ignoring the formatting and I’m not sure how to fix it.

    I’ve tried 2 different functions and they both work as far as controlling the length of text that appears, but there’s that formatting issue.

    Here’s what I have:

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'custom_trim_excerpt');
    
    function custom_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 = 200;
    $words = explode(' ', $text, $excerpt_length + 1);
    if (count($words) > $excerpt_length) {
    array_pop($words);
    array_push($words, '...');
    $text = implode(' ', $words);
    }
    }
    return $text;
    }

    I also tried switching to this and it was even worse:

    function new_excerpt_more($post) {
    	return '<div class="button"><a>ID) . '">' . 'Read More' . '</a></div>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
    add_filter('excerpt_length', 'my_excerpt_length');
    function my_excerpt_length($length) {
        if(in_category(999)) {
            return 200;
        } else {
            return 200;
        }
    }

    Both of these solutions don’t allow the H1, H2, p, br, or any other tags that are normally there…

    Anyone know where I can find an answer to this one? I’ve been searching for tooooooo long and couldn’t find anything.

  • The topic ‘Styling content that uses excerpt_length function’ is closed to new replies.