WordPress.org

Ready to get started?Download WordPress

Forums

How to make Shortcodes execute inside Excerpt (3 posts)

  1. ssdesign
    Member
    Posted 3 years ago #

    Hi,
    I am using WP 3.1.1

    I want to execute shortcodes inside excerpts.
    Now I did my research before posting it here and I found that by adding this code in my Theme's function.php I can achieve what I want:

    add_filter( 'the_excerpt', 'shortcode_unautop');
    add_filter( 'the_excerpt', 'do_shortcode');

    But after I added this code, it still does not execute shortcodes in excerpts.

    I suppose this method is for older versions of WP.
    Is there a similar solution for WP 3.1.1?

    Thanks and Regards

  2. ssdesign
    Member
    Posted 3 years ago #

    any way out of this problem??

  3. alchymyth
    Forum Moderator
    Posted 3 years ago #

    you might need to write a new filter function to deal with your excerpts:
    (this would be added to functions.php of your theme)

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'wp_trim_excerpt_do_shortcode');
    function wp_trim_excerpt_do_shortcode($text) {
    /*NEW OR EDITED CODE*/
    }

    the original code of wp_trim_excerpt() is in /wp-includes/formatting.php
    http://pastebin.com/VtrCqrem
    it might be enough to edit this line:
    $text = strip_shortcodes( $text );
    to:
    $text = do_shortcode( $text );
    and add this new code into your filter function.

    for instance:
    http://pastebin.com/9pS9iCx2

    (utterly untested)

Topic Closed

This topic has been closed to new replies.

About this Topic