@charset "UTF-8";
/*
    Template: swell
    Theme Name: SWELL CHILD
    Theme URI: https://swell-theme.com/
    Description: SWELLの子テーマ
    Version: 1.0.0
    Author: LOOS WEB STUDIO
    Author URI: https://loos-web-studio.com/

    License: GNU General Public License
    License URI: http://www.gnu.org/licenses/gpl.html
*/

//投稿一覧に文字数を表示
function manage_posts_columns($columns) { //項目を追加
  $columns['main_wordcount'] = "本文文字数";
  $columns['title_wordcount'] = "タイトル文字数";
  return $columns;
}
function add_column($column_name, $post_id) {
  global $post;

  if( $column_name == 'main_wordcount' ) {
    $main_word = str_replace( array("\r\n","\r","\n"), '', strip_tags( $post -> post_content)) ;
    $main_word = mb_strlen( $main_word);
    echo $main_word;
  }
  if( $column_name == 'title_wordcount' ) { //SJISに変換してカウント
    $title_word = (strlen(mb_convert_encoding($post -> post_title,'SJIS', 'UTF-8')))/2;
    echo $title_word;
  }
}

add_filter( 'manage_posts_columns', 'manage_posts_columns' );
add_action( 'manage_posts_custom_column', 'add_column', 10, 2 );