Custom Excerpt Length and More Link

If you select the content display to excerpt and you don't have any text in the excerpt field, WordPress automatically displays the first 55 words from the post content and add [...] at the end. Note that more link and HTML tags such as <img>, headings (h1, h2, h3..), link, etc. are stripped in the excerpt output.

This tutorial shows you how to change the default excerpt length and add the more link at the end of the excerpt using Themify themes.

  • Create a custom-functions.php file in the theme folder if you don't have any and paste in the code below. If you already have a custom-functions.php file, simply add the functions.
  • The first function where it specifies 'return 20' is to change the excerpt length to 20 words. You may change the 'return' value to any number as you like.
  • The second function is to add a Read More link at the end of the excerpt. You may change the text 'Read More' to any wording as you like.

<?php

// custom excerpt length
function themify_custom_excerpt_length( $length ) {
   return 20;
}
add_filter( 'excerpt_length', 'themify_custom_excerpt_length', 999 );

// add more link to excerpt
function themify_custom_excerpt_more($more) {
   global $post;
   return ''. __('Read More', 'themify') .'';
}
add_filter('excerpt_more', 'themify_custom_excerpt_more');

?>

Custom Excerpt in Child Theme

If you are creating a Themify child theme, use this function instead of above:


<?php

// Call actions and filters in after_setup_theme hook
add_action( 'after_setup_theme', 'custom_themify_parent_theme_setup' );
function custom_themify_parent_theme_setup() {
   // add more link to excerpt
   function themify_custom_excerpt_more($more) {
      global $post;
      return ''. __('Read More', 'themify') .'';
   }
   add_filter('excerpt_more', 'themify_custom_excerpt_more');
}

?>