• Resolved xsreality

    (@xsreality)


    Hello,

    I am using the gallery shortcode CAPTION and it displays fine when a post is called through the_content() function. But the shortcode is displayed as it is when the post is called through the_excerpt() function. Any way to change that?

    Thanks,
    Abhinav

Viewing 8 replies - 1 through 8 (of 8 total)
  • Not likely. Read about the_excerpt in the Codex: no code or html tags is executed in them.

    xsreality,
    in your loop, you could try the following code:

    <?php
    print apply_filters( 'the_content', $post->the_excerpt );
    ?>

    Just a quick thought – not really tested, but I remember doing something similar to this in the past. I should also state that it is best practice to leave excerpts code free – like moshu suggested. Excerpts are used to build the data that gets inserted into you rss files and I have a seen a few plugins reek havoc on them.

    Good luck

    Thread Starter xsreality

    (@xsreality)

    Thanx moshu and mfields… I have followed your advice and decided against using shortcodes at all. Somehow I find them unnecessarily cumbersome. There are other standard ways to achieve the same thing and I think I will stick to that! ??

    It can be done!

    Add this to your functions.php file in your template. I’ve just tested it out and it works fine ??

    add_filter('the_excerpt', 'do_shortcode');

    @alexleonard

    Which functions.php file? The one attached to the theme?

    add_filter(‘the_excerpt’, ‘do_shortcode’);

    in function.php Where to add it?

    anywhere should work

    I’d like to remove the shortcodes from the_excerpt too. But I can’t get it to work. Is my functions.php correct?

    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'Main Sidebar',
            'before_widget' => '<li><div id="%1$s" class="%2$s">',
            'after_widget' => '</div></li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
    		));
    register_sidebar(array('name'=>'Comments Sidebar',
            'before_widget' => '<li><div id="%1$s" class="%2$s">',
            'after_widget' => '</div></li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
    		));
    register_sidebar(array('name'=>'Footer Sidebar',
            'before_widget' => '<li><div id="%1$s" class="%2$s">',
            'after_widget' => '</div></li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
    		));
    add_filter('the_excerpt', 'do_shortcode');
    ?>

    Thanks for the help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Shortcodes don’t work in excerpts?’ is closed to new replies.