Function to display Custom Field value on Admin post listing page

banner-image

Sometimes we create Custom Fields as per our need to show some extra data on posts or pages. But by default, those field values did not visible on the admin post listing page.

Using the below function, we can display Custom field value with the Edit link on the Post Listing page. Please add the below function on your active theme’s functions.php file.

//Function to display Custom Field value on Admin post listing page
// ADD NEW COLUMN
function custom_columns_head($defaults) {
    $defaults['banner_title'] = 'Banner Title'; //replace 'banner_title' with you custom field name
    return $defaults;
}
 

function custom_columns_content($column_name, $post_ID) {
    if ($column_name == 'banner_title') {
        $banner_title = get_field( "banner_title", $post_ID );
        $edit_link = get_edit_post_link($post_ID);
        if ($banner_title) {
            echo '<a href="'.$edit_link.'">'.$banner_title.'</a>';
        }
    }
}

add_filter('manage_posts_columns', 'custom_columns_head');
add_action('manage_posts_custom_column', 'custom_columns_content', 10, 2);

 

That’s it. Now we will see custom field value on the admin post listing page with a click to edit link.

Tags:

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x