Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the_excerpt on my index page. I'm also using a dropcap shortcode at the beginning of each of my posts. On the index page the posts will not display the letter with the dropcap shortcode around it. If my post beings with the word "Dog" the index page displays "og". How do I get shortcodes to work when using the_excerpt?

Shortcode

    function drcap ($atts, $content = null) {
    return '<div class="dropcap">' . do_shortcode($content) . '</div>';
    }

    add_shortcode('dropcap', 'drcap');
share|improve this question

3 Answers 3

up vote 3 down vote accepted

Paste this in your theme's functions.php file

add_filter( 'the_excerpt', 'shortcode_unautop');
add_filter( 'the_excerpt', 'do_shortcode');
share|improve this answer

In the auto-generated excerpt shortcodes will be removed by Wordpress:

An auto-generated excerpt will also have all shortcodes and tags removed. It is trimmed down to a word-boundary and the default length is 55 words.

Anyhow, if you use the manual excerpt field for your post, it works.

share|improve this answer

Also, add these 2 lines to your functions.php file for complete and comprehensive results:

add_filter('get_the_excerpt', 'shortcode_unautop');
add_filter('get_the_excerpt', 'do_shortcode');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.