Using WordPress ‘register_column_headers()’ PHP function

The register_column_headers() WordPress PHP function registers column headers for a particular screen.

Usage

register_column_headers( $screen, $columns );

Example:

register_column_headers( 'my_custom_screen', array( 'column_id' => 'Column Name' ) );

Parameters

  • $screen (string) – Required. The handle for the screen to register column headers for. This is usually the hook name returned by the add_*_page() functions.
  • $columns (string[]) – Required. An array of columns with column IDs as the keys and translated column names as the values.

More information

See WordPress Developer Resources: register_column_headers()

Examples

Registering Column Headers for a Custom Screen

This example registers column headers for a custom screen called ‘my_custom_screen’.

function my_custom_columns() {
  $columns = array(
    'id' => 'ID',
    'title' => 'Title',
    'date' => 'Date'
  );
  register_column_headers('my_custom_screen', $columns);
}
add_action('admin_init', 'my_custom_columns');

Registering Column Headers for a Custom Post Type

This example registers column headers for a custom post type screen called ‘my_custom_post_type’.

function my_custom_post_type_columns() {
  $columns = array(
    'id' => 'ID',
    'title' => 'Title',
    'date' => 'Date'
  );
  register_column_headers('edit-my_custom_post_type', $columns);
}
add_action('admin_init', 'my_custom_post_type_columns');

Adding a Custom Column to a Taxonomy Screen

This example adds a custom column called ‘Custom Column’ to a taxonomy screen called ‘my_custom_taxonomy’.

function my_custom_taxonomy_columns() {
  $columns = array(
    'cb' => '<input type="checkbox" />',
    'name' => 'Name',
    'custom_column' => 'Custom Column',
    'slug' => 'Slug',
    'posts' => 'Posts'
  );
  register_column_headers('edit-my_custom_taxonomy', $columns);
}
add_action('admin_init', 'my_custom_taxonomy_columns');

Registering Column Headers for a Custom Admin Page

This example registers column headers for a custom admin page called ‘my_custom_page’.

function my_custom_page_columns() {
  $columns = array(
    'id' => 'ID',
    'title' => 'Title',
    'date' => 'Date'
  );
  register_column_headers('toplevel_page_my_custom_page', $columns);
}
add_action('admin_init', 'my_custom_page_columns');

Registering Column Headers for a Custom Submenu Page

This example registers column headers for a custom submenu page called ‘my_custom_submenu_page’.

function my_custom_submenu_page_columns() {
  $columns = array(
    'id' => 'ID',
    'title' => 'Title',
    'date' => 'Date'
  );
  register_column_headers('my-plugin_page_my_custom_submenu_page', $columns);
}
add_action('admin_init', 'my_custom_submenu_page_columns');