WordPress.org

Forums

[resolved] How Do I Customize Post Excerpt Lengths? (5 posts)

  1. jasindall
    Member
    Posted 1 year ago #

    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.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Where did you download this theme from?

  3. jasindall
    Member
    Posted 1 year ago #

    I downloaded it from http://underscores.me/, apparently based on the _s code from Github.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    I'm sorry but as you are using a non-WPORG theme, you need to seek support from the theme's developers - paid or otherwise. We only support themes downloaded from wordpress.org here.

  5. jasindall
    Member
    Posted 1 year ago #

    Thanks for letting know. Now I understand that I'm playing in a different ballpark here and that will narrow my search criteria. Back to the matter of excerpt length, I recently found a link that helped me out:

    http://bavotasan.com/2009/limiting-the-number-of-words-in-your-excerpt-or-content-in-wordpress/

    It's an old post, but it solved the excerpt length problem with the _s theme in both the functions.php file and any given loop.

Topic Closed

This topic has been closed to new replies.

About this Topic