Forums

Add column to post admin page? (3 posts)

  1. ThreeVisual
    Member
    Posted 2 years ago #

    Hey,

    Does anyone know of a plugin, or a way to add another column to the add / manage posts page in the wordpress admin area?

    I have a lot of plugins with extra blocks and I'd like a way to tidy them up a bit.

  2. ThreeVisual
    Member
    Posted 2 years ago #

    anyone have any ideas? thanks.

  3. duck__boy
    Member
    Posted 1 year ago #

    Obviously some function names could do with changing be here you can remove unwanted columns, add new ones and populate the new ones. You can also style the new columns.

    add_action('admin_head', 'header');
    add_filter('manage_posts_columns', 'remove_unwanted_columns');
    add_filter('manage_posts_columns', 'posts_columns', 5);
    add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2);
    
    // Add CSS for new column
    function header(){
    ?>
    	<style type="text/css">
    		table.widefat th.column-riv_post_ids,{
    			width: 50px;
    		}
    	</style>
    <?php
    }
    
    // Remove any unwanted columns
    function remove_unwanted_columns($defaults){
        unset($defaults['comments']);
        return $defaults;
    }
    
    // Create a new column called 'ID'
    function posts_columns($defaults){
        $defaults['riv_post_ids'] = __('ID');
        return $defaults;
    }
    
    // Populate the new column with the Post ID
    function posts_custom_columns($column_name, $id){
    	if($column_name === 'riv_post_ids'){
            echo (int)$id;
        }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.