How Do I Customize Post Excerpt Lengths?
-
Hi, everyone. I’m working with the Underscores theme (_s) in WordPress 3.5.1 and I’m having a problem with customizing the length of post excerpts. I know this issue has been raised several times already, I have tried every plausible coding solution I could find in the theme’s functions.php file, I have deactivated all of my plugins to remove any outside interference, and still nothing works. I’m at my wits’ end here as to what to do. My functions.php file starts with “<?php” at the very top and ends with “?>” at the very bottom, with a slew of functions { } and /** notes */ in between.
The solutions I have tried but to no avail are as followed:
1)
function custom_excerpt_length( $length ) { return 10; // Change this to the number of characters you wish to have in your excerpt } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
2)
function custom_trim_excerpt($text) { // Fakes an excerpt if needed global $post; if ( '' == $text ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $excerpt_length = x; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '...'); $text = implode(' ', $words); } } return $text; }
3)
remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'custom_trim_excerpt');
I hope I’m not stepping out of bounds here, but any help would be appreciated.
- The topic ‘How Do I Customize Post Excerpt Lengths?’ is closed to new replies.