kona333 on "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; } } retu $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'my_custom_excerpt');

Thanks for any help.

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 173 تاريخ : سه شنبه 31 فروردين 1395 ساعت: 9:54