Tuesday, 15 December 2015

How to add new column in default post type [ post,page ] or in custom post type

Process :

#1. Open wordpress directory and find wp-content> themes>your theme > functions.php
#2. Open functions.php in editor you would like and save code as displaying below :


<?php

//  "manage_post_posts_columns" filter to register new custom column
add_filter( 'manage_post_posts_columns', 'set_custom_column' );

// "manage_post_posts_custom_column" action display custom column content

add_action( 'manage_post_posts_custom_column' , 'custom_column_content', 10, 2 );

// function to add a new custom column in post
function set_custom_column($columns) {
   
    $columns['custom_column'] = __( 'Custom Column', 'your_text_domain' );
    return $columns;
}

// function to display custom column content
function custom_column_content( $column, $post_id ) {
            _e( 'My custom Column', 'your_text_domain' ); // here you can apply your code
}
?>

NOTE :  If you would like to add custom column in page just replace 'manage_post_posts_columns' to 'manage_page_posts_columns' and for custom post type replace with 'manage_{$custom_post_type}_posts_columns '

OUTPUT :

No comments:

Post a Comment