Change Excerpt length and Readmore link for custom post type

functions.php

// Excerpt length for different posts type

function new_excerpt_length($length) {
global $post;
if ($post->post_type == ‘post’)
return 12;
else if ($post->post_type == ‘caseresult’)
return 7;
else
return 55;
}
add_filter(‘excerpt_length’, ‘new_excerpt_length’);

// Replaces the excerpt “Read more” text
function new_excerpt_more($more) {
global $post;
if ($post->post_type == ‘post’)
return ‘<a class=”moretag” href=”‘. get_permalink($post->ID) . ‘”> Read post</a>’;
else if ($post->post_type == ‘caseresult’)
return ‘<a class=”moretag” href=”‘. get_permalink($post->ID) . ‘”> Read caseresult</a>’;
else
return ‘<a class=”moretag” href=”‘. get_permalink($post->ID) . ‘”> Read More…</a>’;
}
add_filter(‘excerpt_more’, ‘new_excerpt_more’);

Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: