Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I found the code on the WP Recipies page to force excerpts on the home page:

function my_excerpts($content = false) {
    // If is the home page, an archive, or search results
if(is_front_page() || is_archive() || is_search()) :
    global $post;
    $content = $post->post_excerpt;

// If an excerpt is set in the Optional Excerpt box
    if($content) :
        $content = apply_filters('the_excerpt', $content);

// If no excerpt is set
    else :
        $content = $post->post_content;
        $excerpt_length = 55;
        $words = explode(' ', $content, $excerpt_length + 1);
        if(count($words) > $excerpt_length) :
            array_pop($words);
            array_push($words, '...');
            $content = implode(' ', $words);
        endif;
        $content = '<p>' . $content . '</p>';

    endif;
endif;

// Make sure to return the content
return $content;

}

add_filter('the_content', 'my_excerpts');

But how do I modify that snippet to add a hyperlink to the full post for the "..." part?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Replace the last row of code from:

return $content;

To:

return $content.'<a href="'.get_permalink($post->ID).'">Read More...</a>';
share|improve this answer
    
hi there, thanks for the tip. Is there a way I can have this be right at the end of the excerpt? Right now it shows it after a line break. Example: startupjobsla.com I am using the Coraline template by Automattic. –  noel saw Mar 15 '11 at 5:28
    
simply add a class to the link and style it with CSS –  Bainternet Mar 15 '11 at 13:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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