0

I've read dozens of articles on how to create an excerpt but nothing has worked so far. For testing reasons I use the "Twenty Thirteen" theme, although I developed a child template.

In the index.php of Twenty Thirteen, I put the_excerpt() function in the loop. It looks something like this now:

if ( have_posts() ) :
    /* The loop */
    while ( have_posts() ) : the_post();
        the_excerpt();
    endwhile;
    twentythirteen_paging_nav();
else :
    the_excerpt();
endif;

In the functions.php file I put the following code at the very top:

function new_excerpt_more($more) {        
    // Use .read-more to style the link
    return '...<span class="continue-reading"> <a href="' . get_permalink() . '">'.'Read More »' . '</a></span>';
}
add_filter('excerpt_more', 'new_excerpt_more');

but the complete excerpts are printed out all the time. What am I doing wrong?

1 Answer 1

1

Though it's a bit of unnecessary things to answer your actual question, but for the fact, I used the following code into many of my News Portal WordPress sites, where I had the facilities to Control the excerpt length, and I changed the excerpt More link to my choice. All I did was using my new function echo nano_excerpt(50) instead of using the_excerpt().

<?php
/**
 * Change the excerpt length to some extent
 * where the default is 55.
 *
 * @param  integer $length
 * @return integer
 */
function custom_excerpt_length( $length ) {
    return 200;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

/**
 * Change the excerpt 'more'
 * @return string
 */
function new_excerpt_more() {
    return '... <a class="read-more" href="'. get_permalink( get_the_ID() ) .'">'. __( '&raquo;', 'your-theme' ) .'</a>';
}

/**
 * The excerpt filters
 * @param  integer $limit max limit of words to show
 * @return string
 */
function nano_excerpt( $limit = 75 ) {
    $limited_excerpts = wp_trim_words( get_the_excerpt(), $limit, new_excerpt_more() );
    return $limited_excerpts;
}

Just paste 'em into your functions.php and use the new function echo nano_excerpt($limit) - mentioning the limit of words you want, or leave it blank to show the default 75 words.

Source: http://codex.wordpress.org/Function_Reference/the_excerpt

1
  • Awesome, finally that worked, thanks. Anyway, it is strange that the_excerpt does not work. Thanks for your help Mayeenul.
    – enne87
    Commented Dec 5, 2014 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.