2

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!

2

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;
    }
  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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