Back to Top

Multiple Excerpt WordPress

Excerpt is a short description of the post content.  To add excerpt in wordpress we use ” the_excerpt( ) ” & it adds a little description of the post.

But if we want to use different excerpt for different post types then we can approach like this :-

<?php 
function multiple_excerpt($more) 
{
    global $post;

    if($post->post_type == 'post-type-name')
      return ' <a class="main-color" title="read more" href="'. get_permalink() . '"> More Info...</a>';

    return ' <a class="main-color" title="show more" href="'. get_permalink() . '">[...]</a>';
}

add_filter('excerpt_more', 'multiple_excerpt');
?>

 

If we want to use excerpt of more content on a post type ( i.e. post ) and less content on  some custom post type then we can also customise its length according to the post type.

For this we can approach like this:-

<?php
function new_excerpt_length($length) {
  global $post;
  if ($post->post_type == 'post')
    return 50;
  elseif ($post->post_type == 'post-type-name')
    return 22;
  else
    return 26;
  
}
add_filter('excerpt_length', 'new_excerpt_length');
?>

Support

Still have any issue feel free to add a ticket and let us know your views to make the code better https://webkul.uvdesk.com/en/customer/create-ticket/

Thanks for Your Time! Have a Good Day!

 

. . .

Leave a Comment

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


2 comments

  • Varun Vashistha
  • Thakur Amit Chauhan
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home
    On this page

    Table of Content

    Back to top