this filter
is on the WordPress Codex …
add_filter('excerpt_more', 'new_excerpt_more');
function new_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> … </a>';
}
This works perfect, however I wonder if it is also possible to create a filter that extends the_excerpt()
with the same parameter like the_content()
where it is possible to set the “more-link-text” as parameter?
So I wonder how I can achieve this …
`the_excerpt(‘custom more link’)“
This would be especially useful for me because I have multiple custom-post-types where I always use the_excerpt()
as teasers. Since those custom-post-types have various contexts and meanings it would be nice to have different “more-links” at the end …
Is this somehow possible?
Thank you in advance!
1 Answer
You can use get_post_type
add_filter('excerpt_more', 'new_excerpt_more');
function new_excerpt_more($more) {
global $post;
$post_type = get_post_type($post);
switch( $post_type ):
case 'event':
$teaser="<a class="moretag" href="". get_permalink($post->ID) . '"> More events </a>';
break;
case 'post':
$teaser="<a class="moretag" href="". get_permalink($post->ID) . '"> … </a>';
break;
default
$teaser="";
endswitch;
return $teaser;
}