Want to add links back into excerpts, can do paragraphs so far
-
I found a helpful function to put paragraph tags back into excerpts on the front page posts. It expands the word count to 100. I also want to put links back into the excerpts, but I’m not versed enough to modify this code.
I assume this line –-
$text = strip_tags($text, '<p>');
— keeps the paragraph breaks in. Here’s my question: How do I modify this so that<a>
tags are also kept?I tried
$text = strip_tags($text, '<p>', '<a>');
but that broke the site for a moment.The full function used:
function my_custom_excerpt($text) { global $post; if ( '' == $text ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace('\]\]\>', ']]>', $text); $fulltext = str_replace('\]\]\>', ']]>', $text); $text = strip_tags($text, '<p>'); $excerpt_length = 100; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '... <a href="'. esc_url( get_permalink() ) . '">Read more »</a>'); $text = implode(' ', $words); } else { $text = $fulltext; } } return $text; } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'my_custom_excerpt');
Thanks for any help.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Want to add links back into excerpts, can do paragraphs so far’ is closed to new replies.