如何删除WordPress中的图库快捷代码?

时间:2011-08-01 作者:enjoylife

Your `warmHome_cutstr` function causes in the inline stylesheet of the gallery to be displayed. See gallery-post.jpg.[http://themes.trac.wordpress.org/attachment/ticket/4560/gallery-post.jpg][1] To solve this, you need to hook into the_content and remove the gallery shortcode. In functions.php:

    add_filter( \'the_content\', \'warmHome_content_filter\' );
    function warmHome_content_filter( $text )  {
        $text = strip_shortcodes( $text );
        return $text;
    }
以下是我的warmHome_cutstr 作用如何更正。我已经添加了上述功能。但不知道如何删除库短代码。

function warmHome_cutstr($string, $length) {
             $string =strip_tags($string);
         $strcut= \'\';
         if(strlen($string) > $length) {
        preg_match_all("/[\\x01-\\x7f]|[\\xc2-\\xdf][\\x80-\\xbf]|\\xe0[\\xa0-\\xbf][\\x80-\\xbf]|[\\xe1-\\xef][\\x80-\\xbf][\\x80-\\xbf]|\\xf0[\\x90-\\xbf][\\x80-\\xbf][\\x80-\\xbf]|[\\xf1-\\xf7][\\x80-\\xbf][\\x80-\\xbf][\\x80-\\xbf]/", $string, $info);
         $j = 0;
        for($i=0; $i<count($info[0]); $i++) {

                $strcut .= $info[0][$i];

                $j = ord($info[0][$i]) > 127 ? $j + 2 : $j + 1;
                if ($j > $length - 3) {
                        return $strcut." ...";
                }
        }
        return join(\'\', $info[0]);
                 } else {
                          return $string;
                 }
} 

2 个回复
最合适的回答,由SO网友:Jeremy Jared 整理而成

要完全删除Gallery短代码,请将其添加到主题功能中。php文件:

remove_shortcode(\'gallery\', \'gallery_shortcode\');

SO网友:Vital Lokossou

如果您想在单个php中删除gallery短代码,下面是一种方法。if(has_shortcode(get_the_content(), \'gallery\')){ $pattern = get_shortcode_regex(); echo preg_replace("/$pattern/s", \'\', get_the_content()); }?>

结束

相关推荐