Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Last active June 28, 2020 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanaf1979/e6bdc9cb0ee2defec51a8c2911fca046 to your computer and use it in GitHub Desktop.
Save vanaf1979/e6bdc9cb0ee2defec51a8c2911fca046 to your computer and use it in GitHub Desktop.
Add a column to the WordPress posts overview/list.
<?php
/**
* add_view_post_overview_column.
*
* Add a column to the posts overview/list.
*
* @see https://since1979.dev/___/
* @uses __() https://developer.wordpress.org/reference/functions/__/
*/
function add_view_post_overview_column($columns)
{
$cols = array();
foreach ($columns as $col_name => $col_data) {
$cols[$col_name] = $col_data;
if ($col_name === 'title') {
$cols['viewpost'] = __('View post', 'namespace');
}
}
return $cols;
}
/**
* Hook: manage_posts_columns.
*
* @uses add_action() https://developer.wordpress.org/reference/functions/add_action/
* @uses manage_posts_columns https://developer.wordpress.org/reference/hooks/manage_posts_columns/
*/
add_filter('manage_posts_columns', 'add_view_post_overview_column', 20);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment