想要在阅读文章的时候比较人性化的显示这篇文章的字数统计,可以在自己主题中添加对应的代码,无需使用插件直接可以使用到的,其实很多国外的主题都有开启,但因为中文和英文字符长度的计算不同会造成计算不准确的情况,通过查看字数能够提高工作效率的,荒岛本次带来 WordPress 文章免插件添加字数统计显示的教程,只要将下面的代码添加到主题的「functions.php」文件即可。
// 荒岛一座藏有宝藏的小岛 function count_words ($text) { global $post; $output = ''; if ( '' == $text ) { $text = $post->post_content; if (mb_strlen($output, 'UTF-8') < mb_strlen($text, 'UTF-8')) $output .= '<span class="word-count"><i class="be be-paper"> </i>' . mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8') . ''.sprintf(__( '字' )).'</span>'; return $output; } }宝藏内容来自荒岛-https://x-imagine.com/wordpress-statistical-article-word-count.html宝藏内容来自荒岛-https://x-imagine.com/wordpress-statistical-article-word-count.html
请按 Ctrl+D 收藏荒岛分享给好友 如您发现本文件已经失效无法下载请联系站长修正
荒岛公众号
扫一扫关注

HDsoft27
公众号ID已复制,前往微信关注...
荒岛小程序
扫一扫关注

ximagine
哔哩姬ID已复制,前往B站关注...