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:

  • Twitter
  • Facebook
  • Pocket
  • Print
  • WhatsApp
  • Email

Related

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

Leave a Reply Cancel 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 Change the Welcome/Login Screen in Windows XP ?
  • h4x0r ( Hacker ) - Blogger Template
  • Windows Vista CD key
  • Add/Remove page/Post View Counter Widget For Blogger
  • Free Online Angry Birds game
  • How to Make Your Own Avatar
  • How to Download Documentation for offline viewing - Dash
  • How To Change Windows XP Shutdown Dialog Box

Get Latest post in your Inbox

Random Posts

[How-To] To Send Blank Scarp In Orkut

December 17, 2007 By Ritesh Sanap Leave a Comment

Orkut Keyboard Shortcuts

August 11, 2008 By Ritesh Sanap Leave a Comment

How to Show sidebar or widgets only on Home page or Post page

June 30, 2009 By Ritesh Sanap 6 Comments

Google Voice invites for students

May 14, 2010 By Ritesh Sanap Leave a Comment

Team Viewer

June 7, 2009 By Ritesh Sanap 5 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

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