Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('the_content', 'alc_autoshort_content');
- //a filter to turn the content of posts without the more-tag into excerpts///alchymyth 10/2011//
- function alc_autoshort_content( $content ) {
- if( !is_singular() ) : // don't do it for single posts and pages
- global $post;
- if(!strpos($post->post_content,'<!--more')) {
- // check for the 'more-tag' and leave posts with 'more-tag' unchanged
- $text = do_shortcode( $content ); // otherwise make an excerpt
- $text = strip_tags($text);
- $excerpt_length = apply_filters('excerpt_length', 55);
- $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
- $words = explode(' ', $text, $excerpt_length + 1);
- if (count($words)> $excerpt_length) {
- array_pop($words);
- $text = implode(' ', $words);
- $text = $text . $excerpt_more;
- // add the [...] or a possible link at the end of the shortened post
- } else {
- $text = implode(' ', $words) . $excerpt_more;
- // add [...] or possible link even at the end of a short post
- }
- $content = $text;
- }
- endif;
- return $content;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement