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

Set multiple excerpt length for custom post type wordpress

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.

Set multiple excerpt length for custom post type wordpress

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

Set multiple excerpt length for custom post type wordpress
Set multiple excerpt length for custom post type 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.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.