How to remove a shortcode from the homepage excerpts?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2889 Reply

    Anonymous

    Hi again,
    I am using astroid with a plugin that generate a box with tabs on my posts.
    In order to embed this box in my posts I simply put (manually) the plugin’s shortcode in the post.
    When users enter the post they see the box properly (without seeing the actual shortcode) but unfortunately the shortcode can still be seen in the post’s excerpts that appear on the homepage…

    url is artikelskribenten dot se

    How can I remove the shortcode from the homepage excerpts?
    In other words, how can I remove [tab name=”Om oss”] from the homepage excerpts?

    Thx,
    Jenny

    #2890 Reply

    Ron
    Keymaster

    Hi Jenny

    Try to add this on your functions.php (preferably on a child theme)

    function modify_excerpt( $text ) {
    	$text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text);
    	return $text;
    }
    add_filter( 'the_excerpt', 'modify_excerpt' );
    #2891 Reply

    Anonymous

    Sweet! It works 😉
    Big thanks!

    Jenny

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: How to remove a shortcode from the homepage excerpts?
Your information: