11 次查询 耗时 0.082 秒
本文共计398个字,0条留言,预计阅读时长2分钟
登录/注册
  • 首页
  • >
  • Notes
  • >
  • WordPress统计文章字数函数
  • WordPress统计文章字数函数

    作者:Misshylsay

    日期:2020年08月20日

    使用函数怎么统计文章共写了多少个字?

    //文章字数统计
    function count_words ($text) {  
        global $post;  
        if ( '' == $text ) {  
            $text = $post->post_content;  
            if (mb_strlen($output, 'UTF-8') < mb_strlen($text, 'UTF-8')) $output .= '共写了' . mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8') . '个字';  
            return $output;  
        }  
    }

    直接把上述函数放到主题的function.php文件中保存。

    记得,一定要保存到?>标签前面,小白容易犯的错误。

    使用方法:

    在需要显示的地方输入如下代码即可

    <?php echo count_words ($text);?>

     

    “WordPress统计文章字数函数”共有0条评论

    发表评论

    B em del U Link Code Quote