WordPress Add Shortcodes To Excerpts

By default, WordPress does not allow shortcodes to be executed in excerpts. To enable shortcodes in WordPress excerpts, you need to add the following code to your theme’s functions.php file:

add_filter('the_excerpt', 'do_shortcode');

This code adds a filter to the the_excerpt function, which runs the do_shortcode function on the excerpt before it is displayed. The do_shortcode function allows shortcodes to be executed in the excerpt.

After adding the code, any shortcodes included in the post content will be executed and displayed in the excerpt. For example, if you have the following shortcode in the post content:

[example_shortcode]

The output of this shortcode will be displayed in the excerpt. Note that not all shortcodes are suitable for use in excerpts, and some may cause unexpected results or break the layout of the excerpt.

Leave a Comment