Last active
August 29, 2015 14:05
-
-
Save stephenharris/94246e7b5d709ba6a6ec to your computer and use it in GitHub Desktop.
Insert columns in a WordPress admin table in specific order (example).
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 | |
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