1

The following functions.php edit (contributed by helgatheviking on the themeshaper forums) allows the use of a "Read More" link with custom excerpts.

My problem is simply this: I'm inept at editing functions.php code, but I'd like to safely remove the "wrap excerpt in p tag" portion of this script.

How would I do so?

Thanks.

Original script is found here: http://themeshaper.com/forums/topic/enclosing-excerpt-in-paragraph-tag-038-adding-a-custom-read-more-link

// excerpt read more links and wrap excerpt in p tag
function all_excerpts_get_more_link($post_excerpt) {
    return '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
}
add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
1
  • around the "continue reading" or the actual excerpt text
    – MartinJJ
    Jun 25, 2011 at 20:47

2 Answers 2

2

This should remove the <p> tags, but leave the styling by replacing the paragraph tag with a <span> class:

function all_excerpts_get_more_link($post_excerpt) {
    return '' . $post_excerpt . '' . '<span class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</span>';
}
add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
1
  • Thanks, Jeremy and Javier. The wrapping paragraph tags were introducing validation errors, so I'm glad to be rid of them.
    – user5486
    Jun 26, 2011 at 2:11
1

Delete the empty '' it makes no sense on leaving them:

function all_excerpts_get_more_link($post_excerpt) {
    return $post_excerpt . '<span class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</span>';
}
add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
1
  • I left them in case they wanted to add the surrounding '<p>' tags. Good catch though. Notice I already changed the "p class" to "span class". I wasn't positive which paragraph tag they were referring to so I removed both but left the '' for simple restoration. Jun 26, 2011 at 0:07

Your Answer

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

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