Set the 2 or many excerpt lengths for different custom post type

Sponsors

From wordpress 3.0 version wordpress intruded the custom post type function. Many wordpress theme developers are using custom post type method for showing different sections.

Many times we need to change the excerpt text length and showing on main landing page of custom psot type.

Set the 2 or many excerpt lengths for different custom post type in wordpress

Set the 2 or many excerpt lengths for different custom post type in wordpress

You can set the different excerpt length for each custom post type. you just need to open functions.php file and put following code in file.


function new_excerpt_length($length) {
global $post;
if ($post->post_type == 'post')
return 32;
else if ($post->post_type == 'products')
return 65;
else if ($post->post_type == 'testimonial')
return 75;
else
return 80;
}
add_filter('excerpt_length', 'new_excerpt_length');

Using above code you can set the many excerpt lengths for your custom post type.

If you are still facing issue with custom post then please do write to me.

Incoming search terms:

You may like following Articles!

2 thoughts on “Set the 2 or many excerpt lengths for different custom post type

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>