In which I explain how to display a new column in the Wordpress Admin Posts list

PHPIf your WordPress theme and/or plugin defines custom post types, you may want to show these in the WP Admin Posts list. You can do that by adding a few lines to your theme’s functions.php file.

You can prefix your custom function names however you like. I use dvg_ as a prefix — in addition to the !function_exists() check — to ensure mine won’t conflict with any other core function names.

    /*-----------------------------------------------------
        If this page is being called from the WP Admin
    -----------------------------------------------------*/
    if ( is_admin() ){
        add_filter( 'manage_post_posts_columns', 'dvg_post_table_head' );
        add_action( 'manage_post_posts_custom_column', 'dvg_post_table_content', 10, 2 );
    }

    if ( !function_exists( 'dvg_post_table_head' ) ) {
        function dvg_post_table_head( $defaults ) {
            $defaults['post_type']  = 'Post Type';
            return $defaults;
        }
    }
    if ( !function_exists( 'dvg_post_table_content' ) ) {
        function dvg_post_table_content( $column_name, $post_id ) {
            if ( $column_name == 'post_type' ) {
                $status = get_post_format() ? : 'standard';
                echo ucfirst( $status );
            }
        }
    }

Post the first comment:

I'll never share your email address and it won't be published.

What Is This?

davidgagne.net is the personal weblog of me, David Vincent Gagne. I've been publishing here since 1999, which makes this one of the oldest continuously-updated websites on the Internet.

bartender.live

A few years ago I was trying to determine what cocktails I could make with the alcohol I had at home. I searched the App Store but couldn't find an app that would let me do that, so I built one.

Hemingway

You can read dozens of essays and articles and find hundreds of links to other sites with stories and information about Ernest Hemingway in The Hemingway Collection.