ThemeShaper Forums » Thematic

[closed]

customizing manual excerpt

(2 posts)
  • Started 3 years ago by AnotherAndrew
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. AnotherAndrew
    Member

    I have been scouring the net for some ideas, and banging out some code, but have come up to a wall trying to figure this one out.

    And starting to think this is beyond WP's functionality!

    I want users to be able to specify a manual excerpt in the post editor, and allow them to include html tags such as an image, and link.

    So far, I have been able to set automatic excerpts to allow for html tags through this

    // ALLOW html tags in excerpts
    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, '<img><span><a>');
    		$excerpt_length = 90;
    		$words = explode(' ', $text, $excerpt_length + 5);
    		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');

    But for manual excerpt customizing, I can only seem to allow an add a "read more" link text through this

    add_filter('get_the_excerpt', 'manual_excerpt_more');
    function manual_excerpt_more($excerpt) {
    	$excerpt_more = '';
    	if( has_excerpt() ) {
        	$excerpt_more = ' <a href="'.get_permalink().'" rel="nofollow">...continue reading</a>';
    		$excerpt_more = strip_tags($excerpt_more, '<img><span><a>');
    	}
    	return $excerpt . $excerpt_more;
    }

    As you can see I tried to add in html tags with $excerpt_more = strip_tags($excerpt_more, '<p><img><span><a>'); but this does not seem to work.

    Anyone have suggestions?

    Posted 3 years ago #
  2. maybe something here will help:
    http://forums.themeshaper.com/topic/how-to-make-excerpts-roll-over-and-say-uncle

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.