• Creator
  • #3731

    Is is possible to use the Admin Columns class to create custom columns without creating any custom fields?

Viewing 1 replies (of 1 total)
  • Author
  • #3735
    Anh Tran

    Yes, but that requires some custom code. Here is what I tried:

    – In your plugin file or theme’s functions.php add this code:

    add_action( 'admin_init', 'prefix_custom_post_column', 20 );
    function prefix_custom_post_column() {
    	require_once 'custom.php';
    	new Test_Admin_Columns( 'post', array() );

    – Create a new file custom.php and enter the following code:

    class Test_Admin_Columns extends MB_Admin_Columns_Post {
    	public function columns( $columns ) {
    		$columns = parent::columns( $columns );
    		 * Add more column in a specific position
    		 * @param string $position New column position. Empty to not specify the position. Could be 'before', 'after' or 'replace'
    		 * @param string $target The target column. Used with combination with $position
    		$position = '';
    		$target   = '';
    		$this->add( $columns, 'column_id', 'Column Title', $position, $target );
    		// Add more if you want
    		return $columns;
    	public function show( $column, $post_id ) {
    		switch ( $column ) {
    			case 'column_id':
    				echo 'Column content';
    			// More columns

    Note that the call new Test_Admin_Columns( 'post', array() ); is specific for post. You can change it to any custom post type if you want.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom columns’ is closed to new replies.