Skip to content

Instantly share code, notes, and snippets.

@stephenharris
Last active August 29, 2015 14:05
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 stephenharris/94246e7b5d709ba6a6ec to your computer and use it in GitHub Desktop.
Save stephenharris/94246e7b5d709ba6a6ec to your computer and use it in GitHub Desktop.
Insert columns in a WordPress admin table in specific order (example).
<?php
function set_custom_CPT_columns( $columns ) {
//Insert 'Until' before 'date'
$index = array_search( "date", array_keys( $columns ) );
if( $index !== false ){
$before = array_slice( $columns, 0, $index );
$after = array_splice( $columns, $index, count( $columns ) );
$columns = $before + array( 'until' => __( 'Until' ) ) + $after;
}
//Insert columns after 'title'
$index = array_search( "title", array_keys( $columns ) );
if( $index !== false ){
$before = array_slice( $columns, 0, $index + 1 );
$after = array_splice( $columns, $index + 1, count( $columns ) );
$columns = $before + array(
'p_excerpt' => __( 'Details', 'textdomain' ),
'p_shortcode' => __( 'Shortcode', 'textdomain' ),
'p_image' => __( 'Preview' )
) + $after;
}
return $columns;
}
add_filter( 'manage_edit-CPT_columns', 'set_custom_CPT_columns', 50 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment