0

I have a blog where the excerpt length is set to 55 words and after that it automatically inserts the read more link. What I want to do is to manually determine the excerpt length by inserting a read more tag on the post edit page. Sometimes I want to keep the excerpt to 30 words and sometimes 45, how can I achieve that?

Many thanks...

0

There is a build in meta box to handle custom excerpts. You just need to check the excerpt option box under screen options in your post screen, once checked, you will see the excerpt editor box below your WYSIWYG editor metabox.

For custom post types, make sure that you set the excerpt as support feature in your arguments when registering your post type

'supports' => ['excerpt'],

Wordpress will use your manual excerpt if set above the default excerpt calculated to 55 words from the post content

EDIT

I have quickly searched how to to add the read more link to manual excerpts in Genesis, and came up with the following solution (Thanks to wpmayor.com which states that this solution is compatible with Genesis)

function manual_excerpt_more( $excerpt ) {
    $excerpt_more = '';
    if( has_excerpt() ) {
        $excerpt_more = '&nbsp;<a href="' . get_permalink() . '" rel="nofollow">[Read more]</a>';
    }
    return $excerpt . $excerpt_more;
}
add_filter( 'get_the_excerpt', 'manual_excerpt_more' );
| improve this answer | |
  • Hi, thanks for the answer. I checked the excerpt option and put my excerpt manually but this time read more button has disappeared... This is the code I use to display the button: // Add Read More Link to Excerpts add_filter('excerpt_more', 'get_read_more_link'); add_filter( 'the_content_more_link', 'get_read_more_link' ); function get_read_more_link() { return '...&nbsp;<a href="' . get_permalink() . '"> <button class="read-more">Continue</button></a>'; } – user73593 Jun 10 '15 at 7:38
  • Please see my edit. According to the link I have supplied, they say that the solution works on Genesis. Good luck – Pieter Goosen Jun 10 '15 at 8:31
  • My pleasure. Enjoy ;-) – Pieter Goosen Jun 10 '15 at 8:36
0

Add a custom field in your backend named excerpt_length (really simple, if you have issues, see this video).

In your functions.php add this:

global $wp_query;
$postid = $wp_query->post->ID;                  
$excerpt_length = get_post_meta($postid, 'excerpt_length', true);
function custom_excerpt_length( $length ) {
    return $excerpt_length;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

Now in every post you will manually enter in that custom field the number of characters you want in the excerpt.

| improve this answer | |
  • Hi, when I used the code above all the excerpt disappeared and I had only read more button visible. Also, I haven't gotten any additional option to set the excerpt length on the post edit page. What I want to accomplish is wherever I insert the read more tag, I want the excerpt to be any text up until that point. P.S I am using Genesis child theme if that makes any difference... – user73593 Jun 10 '15 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy