In this article, we’ll see how to Add Custom Column in Posts Admin Screen.
WordPress is known for its extensibility and flexibility, empowering developers and content creators to build dynamic websites with ease. One area where WordPress truly shines is its robust admin interface, which provides a wealth of features and options for managing content.
We’ll explore how to enhance the WordPress admin experience by adding Custom Column in Posts Admin Screen. This customization allows you to display additional information about your posts, giving you quick insights and streamlining your content management workflow.
Add Custom Column in Posts Admin Screen
By default, WordPress shows ID, Post Title, Post Date and Post Status as columns in posts list screen. Sometimes you need to add additional column such as meta fields, featured image on admin column. For that you can follow below steps.
The Posts screen in the WordPress admin is where you manage and organize your site’s blog posts. By default, the screen displays columns such as Title, Author, Categories, Tags, Date, and more. However, depending on your specific needs, you may want to display additional information about your posts, such as post views, custom metadata, or any other relevant data.
If you want to add new columns to the posts overview, WordPress provides hooks to create Custom Column in Posts Admin Screen and their associated data for a custom post type are manage_{$post_type}_posts_columns
and manage_{$post_type}_posts_custom_column
respectively, where {$post_type}
is the name of the custom post type.
For Example, if you want to add the Start and End Date Field in the Event Post type list screen in admin, you need to add the following code in the functions.php file inside the child theme:
function customdate_event_modify_columns( $columns ) { // New columns to add to table $new_columns = array( 'start_date' => __( 'Event Start', 'customdate_textdomain' ), 'end_date' => __( 'Event End', 'customdate_textdomain' ) ); // Remove unwanted publish date column unset( $columns['date'] ); // Combine existing columns with new columns $filtered_columns = array_merge( $columns, $new_columns ); // Return our filtered array of columns return $filtered_columns; } // Let WordPress know to use our filter add_filter('manage_event_posts_columns' , 'customdate_event_modify_columns');
Please note that “customdate” here should be a unique name for your plugin or theme.
If you’ve completed step one above and looked at your edit.php screen, you’ll notice that your new column headings are there but that the cells underneath these columns are empty. now add the following code in the functions.php file in your child theme to display data on two Custom Column in Posts Admin Screen:
function customdate_event_custom_column_content( $column ) { // Get the post object for this row so we can output relevant data global $post; // Check to see if $column matches our custom column names switch ( $column ) { case 'start_date' : // Retrieve post meta $start = get_post_meta( $post->ID, 'event_start', true ); // Echo output and then include break statement echo ( !empty( $start ) ? date( "m/d/y h:i A", $start ) : '' ); break; case 'end_date' : // Retrieve post meta $end = get_post_meta( $post->ID, 'event_end', true ); // Echo output and then include break statement echo ( !empty( $end ) ? date( "m/d/y h:i A", $end ) : '' ); break; } } // Let WordPress know to use our action add_action( 'manage_event_posts_custom_column', 'customdate_event_custom_column_content' );
After Then, You can see two new columns start and end dates with data. this can be a very useful WordPress function. if you want to use any custom admin column in the post list screen on admin.
Customizing the Posts screen in the WordPress admin by adding Custom Column in Posts Admin Screen is a powerful way to enhance your content management workflow. By displaying additional information about your posts, you can gain quick insights and streamline your day-to-day tasks. Leveraging WordPress hooks, filters, and custom fields, you can easily define and populate custom columns, giving you the flexibility to showcase any relevant data.
Whether you’re a developer building a custom theme or a content creator managing a website, adding Custom Column in Posts Admin Screen empowers you to tailor the WordPress admin interface to your specific needs. Embrace this customization and unlock a more efficient and personalized WordPress admin experience.