php - different excerpt length on wordpress -
i want register custom length of excerpt on wordpress plugin. if i add custom excerpt length on plugin , if user's theme have custom excerpt length registered, make conflict? noticed fucntion name different filter's tag same('excerpt_length'). so, please let me clear that.
here excerpt length's code.
function custom_excerpt_length( $length ) { return 40; } add_filter( 'excerpt_length', 'custom_excerpt_length');
thanks.
i use highly customized excerpt output (modified aaron russell's code). won't conflict else have. can remove text values @ will. removes filters excerpt output , overrides them.
// better excerpt output 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, '... [<a href="' . get_permalink(). '" >read more</a>]'); $text = implode(' ', $words); } } return $text; } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'improved_trim_excerpt');
Comments
Post a Comment