如何在 WordPress 查看內容的字數有多少?這是新手架設 WordPress 網站時經常會遇到的問題。本題的解法主要有四種,如下:
解法一:WordPress 內建有字數統計的功能,在內容編輯的畫面中,前往 [內容總攬]→[大綱檢視] 即可查看內容的總字數。
解法二:如果你的內容是採用傳統編輯器編輯,在左下角也可以看到字數統計。
解法三:WP Word Count 外掛除了能讓你知道內容的字數外,也能將所有內容按照字數進行排序,集中在同一畫面讓你查看。
解法四:你可以透過 WPcode 外掛新增由 WPBeginner 所提供的程式碼片段,以便將內容字數出現在內容清單的欄位上。需要注意的是,此方法不支援繁體中文。
add_filter('manage_posts_columns', 'wpbeginner_add_column');
function wpbeginner_add_column($wpbeginner_wordcount_column) {
$wpbeginner_wordcount_column['wpbeginner_wordcount'] = 'Word Count';
return $wpbeginner_wordcount_column;
}
//Link the word count to our new column//
add_action('manage_posts_custom_column', 'wpbeginner_display_wordcount');
function wpbeginner_display_wordcount($name)
{
global $post;
switch ($name)
{
case 'wpbeginner_wordcount':
//Get the post ID and pass it into the get_wordcount function//
$wpbeginner_wordcount = wpbeginner_get_wordcount($post->ID);
echo $wpbeginner_wordcount;
}
}
function wpbeginner_get_wordcount($post_id) {
//Get the post, remove any unnecessary tags and then perform the word count//
$wpbeginner_wordcount = str_word_count( strip_tags( strip_shortcodes(get_post_field( 'post_content', $post_id )) ) );
return $wpbeginner_wordcount;
}
歡迎加入 Facebook 社團交流討論
驅動部落 – WordPress 與 SEO 學習交流社團