1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| // Ajouter la colonne WordCount de WordPress
add_filter('manage_posts_columns', 'crunchify_add_wordcount_column');
function crunchify_add_wordcount_column($crunchify_columns) {
$crunchify_columns['crunchify_wordcount'] = 'Word Count';
return $crunchify_columns;
}
// Afficher le nombre de mots dans le panneau d'administration
add_action('manage_posts_custom_column', 'crunchify_show_wordcount');
function crunchify_show_wordcount($name)
{
global $post;
switch ($name)
{
case 'crunchify_wordcount':
$crunchify_wordcount = crunchify_post_wordcount($post->ID);
echo $crunchify_wordcount;
}
}
// Obtenir le nombre de mots d'un message individuel
function crunchify_post_wordcount($post_id) {
$crunchify_post_content = get_post_field( 'post_content', $post_id );
$crunchify_final_wordcount = str_word_count( strip_tags( strip_shortcodes($crunchify_post_content) ) );
return $crunchify_final_wordcount;
} |
Partager