As mentioned in previous post WordPress is full of magic and customization. Theoretically you could change, update, enhance anything you want on your blog including Admin panel. By default you couldn’t see how many attachments you have in a post.
In this tutorial we will go over simple tricks on how to show Attachment(s)
column in WordPress Admin Panel for posts.
add_filter('manage_posts_columns', 'crunchify_columns_attachments', 1); function crunchify_columns_attachments($crunchifyCount){ $crunchifyCount['wps_post_attachments'] = __('Attachment(s)'); return $crunchifyCount; } add_action('manage_posts_custom_column', 'crunchify_custom_columns_attachments',1, 2); function crunchify_custom_columns_attachments($crunchify_col_name, $id){ if($crunchify_col_name === 'wps_post_attachments'){ $attachments = get_children(array('post_parent'=>$id)); $crunchifyAttachments = count($attachments); if($crunchifyAttachments !=0) { echo $crunchifyAttachments; } } }
Just add above code to your theme’s functions.php
file and visit Posts -> All Posts
to see added Attachment(s) column.
manage_posts_columns
is a filter applied to the columns shown on the manage posts
screen. It’s applied to posts of all types except pages. To add a custom column for pages
, hook the manage_pages_columns
filter.
manage_posts_custom_column
allows you to add custom columns to the list post/page/custom post type pages (which automatically appear in Screen Options). You don’t need any extra plugin to achieve this additional column.