WordPress Custom Excerpt

/** * CUSTOM EXCERPT *********************************************************************** */ $excerpt_length = 30; // add more link to excerpt function excerpt_read_more_link($output) { global $post; global $excerpt_length; $output = str_replace('<p', '<p class="excerpt"', $output); if( strlen($output) > $excerpt_length ) { return $output . '<p class="more-link"><a href="'. get_permalink($post->ID) . '" class="button"> Read More</a></p>'; } else { return $output; } } add_filter('the_excerpt', 'excerpt_read_more_link'); // excerpt more string function new_excerpt_more( $more ) { return ' ...'; } add_filter('excerpt_more', 'new_excerpt_more', 999); // custom excerpt length function custom_excerpt_length( $length ) { global $excerpt_length; return $excerpt_length; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
WP Function to customize the_excerpt() function from WP default the_excerpt(). Place code in functions.php.

1 Response

echo wp_trim_words( $post -> post_content, $num_words = 70, $more = '...' );

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.