Tutorials for web designers and developers
Tutorials for Developers_
Search
Close this search box.

Fixed: Shortcode appearing in excerpts – WordPress

Hafiz Faraz Mukhtar

Hafiz Faraz Mukhtar

Hafiz Faraz Mukhtar is an expert Web Developer, SEO specialist, and Graphic Designer. Hafiz Faraz is an expert in WordPress design and development. Hire on Upwork | Hire on Fiverr
Wordpress shortcode appearing in excerpts on archive page

Sometimes, shortcodes appear in the post excerpts on the archive page of WordPress site. This is a common issue with excerpts in WordPress due to theme or plugin issues. This can be very easily fixed.

Remember: These methods will work only if the shortcodes are registered with WordPress. If you are trying to remove shortcodes those got remained after deactivation and deleting the plugin then this will not work, because now those shortcodes are not shortcodes anymore, they are just a piece of text for WordPress. In this case, you need to manually do it, sadly.

Solution

Simply add the following code to your theme’s functions.php file. This code simply tells the wordpress to omit any shortcodes appearing in the post exerpts on archive section.

function strip_shortcode_from_excerpt( $content ) {
    $content = strip_shortcodes( $content );
}
add_filter('the_excerpt', 'strip_shortcode_from_excerpt');

Hope so this solution helps you, if you are having any difficulty, please feel free to contact me.

Leave a Reply

Your email address will not be published. Required fields are marked *