@Poremsky.com

Tips & Tricks for Windows, Office, and Whatever

  • Home
  • Windows
  • Office
  • BlackBerry
  • Web Design
  • WordPress
  • Internet Explorer

Part 3: Custom Excerpts

Published on September 15, 2011 Last reviewed on May 3, 2017

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;}
?>

Share this:

  • Facebook
  • LinkedIn
  • Twitter
  • Print
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments

Recent Posts

  • Server drafts location is not valid error message
  • What is the Brown File Box Icon on Files in Windows 11?
  • Remove Office Licenses from Windows
  • Add the Recent Items Folder to Windows 10 Quick Access
  • A New Scam? Cashing in on Kohl's Cash

Recent Comments

  • FUAD on Remove Office Licenses from Windows
  • Brian DuBridge on Add the Recent Items Folder to Windows 10 Quick Access
  • Renee Moodie on Remove Office Licenses from Windows
  • John P on Remove Office Licenses from Windows
  • Puja on Remove Office Licenses from Windows
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

© 2023 · @Poremsky.com

wpDiscuz
Go to mobile version
You are going to send email to

Move Comment