Site icon @Poremsky.com

Part 3: Custom Excerpts

While I was working on the index, I decided I wanted to include a short excerpt instead of just making a list of hyperlinks.

We're using a custom excerpt that was too long and while the RSS excerpt worked ok, I wanted shorter and control over the "more" indicator. I could have solved this problem by adding short excerpts to every page, but that would take forever. 🙂

With a little more searching, I found instructions for creating filters and custom excerpt functions (added to the functions.php file).

This line goes into your template file:

<?php my_excerpt('excerptlength_index', 'excerptmore'); ?>

The function goes into your functions.php

function excerptlength_teaser($length) {    return 45;}
function excerptlength_index($length) {    return 29;}
function excerptmore($more) {    return '...';}

function my_excerpt($length_callback='', $more_callback='') {    
global $post;    
if(function_exists($length_callback)){
add_filter('excerpt_length', $length_callback);    
}    
if(function_exists($more_callback)){        
add_filter('excerpt_more', $more_callback);    }    
$output = get_the_excerpt();    
$output = apply_filters('wptexturize', $output);    
$output = apply_filters('convert_chars', $output);    
$output = '<p>'.$output.'</p>';    echo $output;}
?>
Exit mobile version