Support » Fixing WordPress » How to make Shortcodes execute inside Excerpt

  • 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • any way out of this problem??



    Forum Moderator

    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) {

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

    for instance:

    (utterly untested)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to make Shortcodes execute inside Excerpt’ is closed to new replies.