Support » Requests and Feedback » There is a SERIOUS problem in strip_shortcodes

  • strip_shortcodes is used in get_the_excerpt to strip shortcodes from content before generating the excerpt. This is ok, but that function is based on

    return preg_replace('/'.$pattern.'/s', '$1$6', $content);

    The result is that it does NOT strip ONLY the shortcode, but also ITS CONTENT! So, if you have a shortcode that is embedding the whole post as

    [translate_this]my post content[\translate_this]

    you have an EMPTY excerpt. Is there any hope to change that statement to

    return preg_replace('/'.$pattern.'/s', '$1$4$6', $content);

Viewing 5 replies - 1 through 5 (of 5 total)
  • For the moment I find the following solution that strips selected shortcodes PRESERVING the content.

    [code moderated – please use the pastebin for any code over 10 lines long]

    I use it as follows:

    function get_safe_excerpt($max_length=350,$min_lenght=300) {
    	$cnt = get_the_content();
    	$cnt = strip_tags($cnt);
    	$cnt = strip_selected_shortcodes($cnt);
    	return utf8_truncate($cnt,$max_length,TRUE,BRACKETED_ELLIPSIS,$min_lenght);
    }

    where utf8_truncate is my unicode-safe function to truncate a text.

    For the moment I find the following solution that strips selected shortcodes PRESERVING the content.

    <script src=”http://pastebin.com/embed_js.php?i=5CJKL5id”></script>

    I use it as follows:

    function get_safe_excerpt($max_length=350,$min_lenght=300) {
    	$cnt = get_the_content();
    	$cnt = strip_tags($cnt);
    	$cnt = strip_selected_shortcodes($cnt);
    	return utf8_truncate($cnt,$max_length,TRUE,BRACKETED_ELLIPSIS,$min_lenght);
    }

    where utf8_truncate is my unicode-safe function to truncate a text.

    I really cannot understand how to SHOW the code by pastebin here!!!!

    …and how to remove duplicated posts… sigh….

    you don’t embed or ‘show’ the pastebin here, just give the link to the pastebin page, we go look over there

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘There is a SERIOUS problem in strip_shortcodes’ is closed to new replies.