Best 2 Know

The Ultimate Blogging Resource

  • Advertising
  • WebHosting
  • Contact Us
  • Blogger
    • Blogger Templates
    • Blogger Tutorials
  • Browser
    • Firefox
    • Google Chrome
  • Google
  • Internet
    • Facebook
    • Twitter
  • Thesis
  • Windows
  • WordPress
    • WordPress Themes
    • WordPress Plugins
  • More
    • Linux
    • Review
    • Solutions
    • Announcements

How to Create Multiple Excerpts in WordPress

When we are creating a theme, we sometimes require multiple custom excerpts in a theme. but when ever we use add_filter it affects all the the_excerpt in a theme. So today I will give you a solution to How to Create multiple Excerpts in WordPress

What we are doing today are going to do is a simple solution of creating a custom function for the_excerpt. which we will call out when ever we need excerpts of various sizes (Different Lengths). so for the beginning copy the below code in the functions.php :

// Create the Custom Excerpts callback
function wpden_excerpt($length_callback = '', $more_callback = '')
{
    global $post;
    if (function_exists($length_callback)) {
        add_filter('excerpt_length', $length_callback);
    }
    if (function_exists($more_callback)) {
        add_filter('excerpt_more', $more_callback);
    }
    $output = get_the_excerpt();
    $output = apply_filters('wptexturize', $output);
    $output = apply_filters('convert_chars', $output);
    $output = '<p>' . $output . '</p>';
    echo $output;
}
// Custom Length 
function wpden_mag_len($length) {
    return 200;
}

// Create the Custom Excerpts callback function wpden_excerpt($length_callback = '', $more_callback = '') { global $post; if (function_exists($length_callback)) { add_filter('excerpt_length', $length_callback); } if (function_exists($more_callback)) { add_filter('excerpt_more', $more_callback); } $output = get_the_excerpt(); $output = apply_filters('wptexturize', $output); $output = apply_filters('convert_chars', $output); $output = '<p>' . $output . '</p>'; echo $output; } // Custom Length function wpden_mag_len($length) { return 200; }

once you have saved the above code in functions.php you can call custom excerpt like this :

<?php wpden_excerpt('wpden_mag_len'); ?>

<?php wpden_excerpt('wpden_mag_len'); ?>

Now you can use Custom Excerpt what ever times you want, just copy and paste Custom Length function and call it using Custom Excerpt. Also note that this Custom function also supports <!-- more --> Tag so you can even customize Read More by Following code :

function wpden_more_view($more){
global $post;
return '... &lt;a class="view-article" href="' . get_permalink($post->ID) . '"&gt;' . __('View Article', 'wpden') . '&lt;/a&gt;';
}

function wpden_more_view($more){ global $post; return '... &lt;a class="view-article" href="' . get_permalink($post->ID) . '"&gt;' . __('View Article', 'wpden') . '&lt;/a&gt;'; }

you can call out it together with custom excerpt like showed in code below :

&lt;?php wpden_excerpt('wpden_mag_len','wpden_more_view'); ?&gt;

&lt;?php wpden_excerpt('wpden_mag_len','wpden_more_view'); ?&gt;

So now you don’t need to use filters and can make as many modifications you like to the_excerpt and Create Multiple Excerpts to your liking for theme you are making.

For More information on the_excerpt visit it on WordPress Codex.

Subscribe via Email

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to print (Opens in new window) Print
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to email a link to a friend (Opens in new window) Email

Related

December 24, 2013 Ritesh Sanap WordPress add_filter, functions.php, Hacks, the_excerpt

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post navigation

Previous Previous post: How to Disable Auto Update in WordPress
Next Next post: How to Copy files from Google Drive to DropBox or Box.net – Mover.io

Currently Trending

  • How to download Specific parts of YouTube videos
    How to download Specific parts of YouTube videos
  • Windows Vista CD key
    Windows Vista CD key
  • How to retrieve my Demonoid username
    How to retrieve my Demonoid username
  • How to add Logo to Thesis theme
    How to add Logo to Thesis theme
  • How to Delete Feedbacks from JetPack Contact Form
    How to Delete Feedbacks from JetPack Contact Form
  • List Of All 255 Keyboard All Alt Key Codes
    List Of All 255 Keyboard All Alt Key Codes
  • h4x0r ( Hacker ) - Blogger Template
    h4x0r ( Hacker ) - Blogger Template

Get Latest post in your Inbox

Random Posts

Setting Up Code Blocks

February 7, 2011 By Ritesh Sanap Leave a Comment

I Lost My MotherBoard Driver CD/DVD ! What To Do ??

August 14, 2008 By Ritesh Sanap 1 Comment

How to Brand Windows to your Name

December 25, 2010 By Ritesh Sanap Leave a Comment

All Latest Window’s XP Tip’s & Trick’s

December 28, 2007 By Ritesh Sanap Leave a Comment

How to Display Random Posts

November 26, 2012 By Ritesh Sanap 2 Comments

WordPress

HTTP2 Server Push for W3 Total Cache Minify plugin

August 17, 2016 By Ritesh Sanap 5 Comments

How to Disable Emojis in WordPress

January 6, 2016 By Ritesh Sanap Leave a Comment

JetPack Related posts and Sharing not working with NGINX

November 10, 2015 By Ritesh Sanap Leave a Comment

Simply Pure – WordPress Theme

November 2, 2014 By Ritesh Sanap 2 Comments

Advanced What should we Write about next? – WordPress Plugin

July 28, 2014 By Ritesh Sanap Leave a Comment

How to Disable Self Pingback or TrackBack

January 16, 2014 By Ritesh Sanap Leave a Comment

BlueStrap – WordPress Theme

January 1, 2014 By Ritesh Sanap 15 Comments

How to Create Multiple Excerpts in WordPress

December 24, 2013 By Ritesh Sanap Leave a Comment

How to Disable Auto Update in WordPress

November 21, 2013 By Ritesh Sanap Leave a Comment

How to Delete Feedbacks from JetPack Contact Form

November 19, 2013 By Ritesh Sanap 9 Comments

Recent Posts

  • HTTP2 Server Push for W3 Total Cache Minify plugin
  • How to show hidden files and folders in Mac OS X
  • How to Disable Emojis in WordPress
  • Canva – Online Photo Editor
  • JetPack Related posts and Sharing not working with NGINX

Archives

Recommends

  • DigitalOcean – Cloud Hosting
  • Dropbox – Cloud Storage
  • Elegant Themes – WordPress Themes
  • LastPass – Password Manager
  • Like us on Facebook
  • Follow on Twitter
  • +1 on Google
  • Subscribe via Email
  • RSS Feed

© 2025 Best 2 Know · All Rights Reserved · We ♥ DigitalOcean