Support » Theme: Wisteria » How to NOT include image in Excerpt for latest posts homepage display

  • Hello! I use a post scheduler to publish posts to our WordPress site. The format for the posts is
    {text}

    Image tag

    My problem is that when the post gets posted, the image tag is included in the excerpt. Because of which the homepage display for recent posts has the same image posted twice (as a thumbnail and as a part of excerpt)

    I tried to place a generic code in the functions.php but this doesn’t seem to work. If anyone can help me figure this out, I’ll be super grateful!

     function improved_trim_excerpt($text) {
    	global $post;
    	if ( '' == $text ) {
    		$text = get_the_content('');
    		$text = apply_filters('the_content', $text);
    		$text = str_replace('\]\]\>', ']]>', $text);
    		$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
    		$text = strip_tags($text, '<p>');
    		$excerpt_length = 80;
    		$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');

    Thanks!

    The page I need help with: [log in to see the link]

  • The topic ‘How to NOT include image in Excerpt for latest posts homepage display’ is closed to new replies.