Created
February 15, 2019 11:13
-
-
Save imelgrat/9ce9d97ad2dbfb7ebccd42a3fb586903 to your computer and use it in GitHub Desktop.
Reorder WordPress post-list columns, adding a word-count column after the title column.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Reorder post-list columns, adding a word-count column after the title column. | |
* | |
* This code assumes a new column named "wordcount" was already. | |
* Check the link for the whole process. | |
* | |
* @link https://imelgrat.me/wordpress/customize-wordpress-post-management-page/ | |
* | |
* @param array $defaults List of default post-list columns | |
* | |
* @return array The list of original columns plus the wordcount column | |
*/ | |
function add_wordcount_column($defaults) | |
{ | |
$new_columns = array(); // Create empty array to store new column order | |
foreach ($defaults as $key => $value) | |
{ | |
$new_columns[$key] = $value; // Add columns to new array | |
if ($key == 'title') | |
{ | |
// when we find the title column | |
$new_columns['wordcount'] = 'Word count'; // Add the word-count column after title column | |
} | |
} | |
return $new_columns; | |
} | |
add_filter('manage_posts_columns', 'add_wordcount_column'); // Register filter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment