Using the strip_tags function on node teaser in preprocess_node file I can remove the shortcodes from node teasers.

If I want to remove only the shortcode and no the other tags I should do something like this http://drupal.org/node/659458#comment-6035146

Could anyone help me to change the strip only function to support shortcodes ?


<?php
/* Strip only selcted tags in THEME_preprocess_node function below */
function strip_only($str, $tags) {
    if(!is_array($tags)) {
        $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
        if(end($tags) == '') array_pop($tags);
    }
    foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>]*>#is', '', $str);
    return $str;
}

/* Strip only selected tags from teasers - in this case, embed and iframe */
function YOUR_THEME_preprocess_node(&$vars) {
  if(isset($vars['content']['body'][0]['#markup']) && $vars['teaser']) {
    $vars['content']['body'][0]['#markup'] = strip_only($vars['content']['body'][0]['#markup'], '<iframe> <embed>');
  }
}
?>

Thanks

Comments

manos_ws’s picture

Title: Strip Shortdoce from node teasers » Strip shortcode from node teasers

!!!! shortcode not Shortdoce