Modifying the excerpt AND the "more" link
-
Hello!
I followed this site: http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/ to improve my excerpts. It works fine!
Then I wanted to modify the […] to be clickable and show “read more” instead. I tried to add code like on this page: http://codex.wordpress.org/Customizing_the_Read_More#Displaying_a_.22more.E2.80.A6.22_link_when_using_the_the_excerpt.28.29
But together it won’t work. Only the first code works. But if I remove the first code then it will work.
Obviously I am NOT well versed in PHP…
This is what I tried to put in functions.php
function improved_trim_excerpt($text) { global $post; if ( '' == $text ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace('\]\]\>', ']]>', $text); $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text); $text = strip_tags($text, '<p>'); $excerpt_length = 40; $words = explode(' ', $text, $excerpt_length + 1); if (count($words)> $excerpt_length) { array_pop($words); array_push($words, '[...]'); $text = implode(' ', $words); } } return $text; } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'improved_trim_excerpt'); // end improved excerpt // Replaces the excerpt "more" text by a link function new_excerpt_more($more) { global $post; return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>'; } add_filter('excerpt_more', 'new_excerpt_more');
Thank you for reading, hoping for some help. 🙂
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Modifying the excerpt AND the "more" link’ is closed to new replies.