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');
Paste this in your theme’s functions.php file
In the auto-generated excerpt shortcodes will be removed by WordPress:
Anyhow, if you use the manual excerpt field for your post, it works.
Here’s a solution for including shortcode output within WordPress’s auto-generated excerpts:
This implementation assumes a word-length of 55.
Hope it helps someone.
Also, add these 2 lines to your
functions.php
file for complete and comprehensive results: