Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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) . '"> &hellip; </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!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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) . '"> &hellip; </a>';
               break;

            default
                $teaser = '';
        endswitch;

        return $teaser;
    }
share|improve this answer
    
Thank you, this is ok as well. I just thought there is a way to extend this function with this parameter - would be way more "semantic" to code. –  mathiregister May 23 '12 at 15:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.