• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Custom excerpt length

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Custom excerpt length

This topic is: resolved

Tagged: Excerpt

  • This topic has 4 replies, 3 voices, and was last updated 8 years, 4 months ago by tanyaslogos.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • September 22, 2016 at 7:39 am #193520
    studionoobly
    Member

    How can I set up an excerpt on posts that has a limit of say 35 words/228 characters and then shows a customised 'Read More' link at the end?

    I have tried the following:

    add_filter( 'excerpt_length', 'change_excerpt_length' );
    function change_excerpt_length($length) {
    		return 35;
    }

    But if there are less than 35 words lets say four words then no button shows up?

    I have also tried this:

    add_filter('excerpt_more', 'get_read_more_link');
    add_filter( 'the_content_more_link', 'get_read_more_link' );
    function get_read_more_link() {
    	 return '<a class="button archive-button" href="' . get_permalink($post->ID) . '">Continue&nbsp;Reading&nbsp;<i class="fa fa-angle-right" aria-hidden="true"></i></span></a>';
    }

    But again if there's less than four or five words no button shows up? I have checked Genesis theme settings there is a show excerpt option but no option to control the amount of words or characters.

    Lastly I also tried this:

    function wpm_manual_excerpt_read_more_link($excerpt) {
        $excerpt_more = '';
        if (has_excerpt() && ! is_attachment() && get_post_type() == 'post') {
            $excerpt_more = '&nbsp;<a href="' . get_permalink() . '">[Continue&nbsp;reading] <span class="screen-reader-text">' . get_the_title() . '</span></a>';
        }
        return $excerpt . $excerpt_more;
    }

    But no button...

    Thanks

    http://localhost
    September 22, 2016 at 10:56 am #193536
    Jess
    Member

    This is what I add to my functions.php file to add 'Read More' text to the ends of post excerpts (change the bold text to whatever you'd like):

    // Modify The Read More Link Text
    function new_excerpt_more($more) {
    return ' ... [Read More]';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    And this is what I add to limit the length of those excerpts (change the bolded number to the number of characters you'd like):
    // Change length of post excerpt
    function custom_excerpt_length( $length ) {
    return 30;
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );


    Jess

    September 22, 2016 at 10:58 am #193537
    Jess
    Member

    Ah -- sorry! I forgot to wrap that first chunk of code it the right tags so this site killed some of it. Here's what it should have said:

    // Modify The Read More Link Text
    function new_excerpt_more($more) {
      return ' <a class="read-more" href="' . get_permalink( get_the_ID() ) . '">... [Read More]</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    Jess

    September 23, 2016 at 4:05 am #193576
    studionoobly
    Member

    Thanks Jess,

    I've tried that you can see it in the second snippet of code in my question.

    Fortunately and after much searching I found that this works when I put it into the category templates.

     echo substr(get_the_excerpt(), 0,350).' [...]';
     echo '<a class="button archive-button" href="'. get_permalink( get_the_ID() ).'">Continue&nbsp;Reading&nbsp;</a>';

    you can view the full code here at stackoverflow

    January 22, 2017 at 3:09 pm #199804
    tanyaslogos
    Member

    Thank you Jess!!!! I kept trying the code listed here http://my.studiopress.com/snippets/post-excerpts/#content-more-link and it wouldn't work but your code did the job!

    Thank you so very much! You are the BEST!

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Custom excerpt length’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble