X

Custom column for post type

When creating custom post types, the standard columns(title, author, date etc.) might not be enough for your needs, and this snippet will help you to create your own.

You can add the custom columns for your custom post types by adding this to functions.php. Remember to change POSTTYPE to your post type slug!

Code Snippet:

<?php
add_action('manage_POSTTYPE_posts_columns', 'posts_column_hello', 10);
add_action('manage_POSTTYPE_posts_custom_column', 'posts_custom_column_hello', 10, 2);
function posts_column_hello($defaults){
    $defaults&#91;'post_hello'&#93; = __('Hello World');
    return $defaults;
}
function posts_custom_column_hello($column_name, $post_id){
    switch($column_name) {
        case 'post_hello':
            echo 'hello world'
            break;
    }
}
?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!