Customizing The_Excerpt
-
I wasn’t able to locate this on Google, so I was hoping that someone could help me here.
I’m using the following code to customize the_excerpt output.
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> <em> <i> <b> <strong> <img>'); $excerpt_length = 50; $words = explode(' ', $text, $excerpt_length + 1); if (count($words)> $excerpt_length) { array_pop($words); array_push($words, 'read more...'); $text = implode(' ', $words); } } return $text; } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); remove_action('wp_head', 'rel_canonical'); add_filter('get_the_excerpt', 'improved_trim_excerpt');
Obviously on the page I’m calling the file I just put in the_excerpt()
What I’m wondering, would it be possible to make the_excerpt() a ‘conditional’ kind of tag? A few areas of the site that I’m working on require no “read more” information, where as other sections do. Is there a way to modify the actual call itself?
For example:
<?php the_excerpt('no-read-more');?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Customizing The_Excerpt’ is closed to new replies.