Skip to content

Instantly share code, notes, and snippets.

@rachelbaker
Created January 26, 2012 19:50
Show Gist options
  • Save rachelbaker/1684691 to your computer and use it in GitHub Desktop.
Save rachelbaker/1684691 to your computer and use it in GitHub Desktop.
WordPress Excerpt Related Functions from TwentyTen Theme
<?php
/**
* Sets the post excerpt length to 40 characters.
*/
function twentyten_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
/**
* Returns a "Continue Reading" link for excerpts
* @return string "Continue Reading" link
*/
function twentyten_continue_reading_link() {
return ' <a href="'. get_permalink() . '">' . __( '<div style="text-align:right; clear:both;">Read full post</div>', 'twentyten' ) . '</a>';
}
/**
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
*/
function twentyten_auto_excerpt_more( $more ) {
return ' &hellip;' . twentyten_continue_reading_link();
}
add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
/**
* Adds a pretty "Continue Reading" link to custom post excerpts.
*/
function twentyten_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= twentyten_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment