Last active
February 8, 2016 08:03
-
-
Save hsleonis/002ac255ccbe6065cff3 to your computer and use it in GitHub Desktop.
Create custom column in wordpress admin post or page list
This file contains hidden or 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 | |
if (function_exists( 'add_theme_support' )){ | |
add_filter('manage_posts_columns', 'posts_columns', 5); // All posts column list | |
add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2); // Cloumn content | |
add_filter('manage_pages_columns', 'posts_columns', 5); // All pages column list | |
add_action('manage_pages_custom_column', 'posts_custom_columns', 5, 2); // Cloumn content | |
add_filter('manage_projects_posts_columns', 'posts_columns', 1); // Only custom post 'project' column list | |
add_action('manage_projects_posts_custom_column', 'posts_custom_columns', 1, 2); // Column content | |
} | |
/*function posts_columns($defaults){ | |
$defaults['tmx_post_thumbs'] = __('Thumbs'); // Column title, you can add more columns in $defaults array | |
return $defaults; | |
}*/ | |
function posts_columns($defaults){ | |
foreach($defaults as $key=>$value) { // Reorder columns | |
if($key=='title') { // when we find the title column | |
$new['tmx_post_thumbs'] = __('Thumbs'); // put the thumb column before it | |
} | |
$new[$key]=$value; | |
} | |
return $new; | |
} | |
function posts_custom_columns($column_name, $id){ | |
if($column_name === 'tmx_post_thumbs'){ // print column content | |
if ( !has_post_thumbnail() ) { // Default thumbnail | |
echo '<img height="80" width="80" src="'.trailingslashit( get_stylesheet_directory_uri() ) . 'resources/img/pr-03.jpg" />'; | |
} | |
else { | |
echo the_post_thumbnail( array(125,80) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment