How to Add A Custom Column in CatFolders Document Gallery Using Hooks

If your WordPress Media Library is like a crowded attic – full of images, PDFs, videos, and random uploads – finding the right file can feel like hunting for a needle in a haystack.

Sure, our CatFolders Document Gallery already makes things more organized with folders, but what if you could make it even smarter?

Imagine opening your gallery and instantly seeing extra details tailored to the type of files you work with – image resolution, version number, author, PDF page count, video duration, audio length – without clicking on a single file.

Thatโ€™s the power of adding a custom column. And thanks to WordPress hooks, you can do it without touching CatFoldersโ€™ core code.

Letโ€™s break the rule with WordPress snippets!

If youโ€™re running a content-heavy site, like an online magazine, eCommerce store, course library, design portfolio, or corporate intranet, your media library can easily grow into the thousands of files.

Without the right information at a glance, youโ€™ll spend more time clicking into each file just to check a detail. Thatโ€™s like rummaging through a messy filing cabinet every time you need a single sheet of paper.

By default, the CatFolders Document Gallery gives you basic details like file name and date, which is fine for quick browsing. These built-in options make it easy to show important file details right inside the gallery without extra setup.

Hereโ€™s what you get out of the box:

  • File Name – Displays the exact filename, helping you and your visitors quickly identify files.
  • File Type & Icon – Shows a visual file icon (PDF, Word, Excel, Image, Video, Audio, etc.), making it easy to distinguish between different file formats.
  • File Size – Automatically calculates and displays the size of each file (e.g., 2 MB, 350 KB), useful for monitoring large uploads or download weights.
  • Upload Date – Lists when the file was added to your WordPress Media Library, so you can sort and filter by recency.
  • Download Link or Button – Let users instantly download the file directly from the gallery view.
  • Counter (Click Count) – Tracks how many times a file has been clicked or downloaded, giving you insight into file popularity or usage.
Column to show the information in CatFolders Document Gallery

If you want to display more advanced, file-type-specific details (like caption, video duration, or custom project metadata), you can go beyond the defaults by adding your own custom columns with CatFolders hooks. 

For WordPress users managing media-rich websites, this is a huge productivity boost. Custom column support transforms your Document Gallery from a simple list into a powerful file management hub that adapts to your needs.

Before working with CatFolders hooks, we have to organize all WordPress media files into a cluttered structure and display them as a gallery.

Step #1: How to Add Captions for Media Files in WordPress Library

On your WordPress website, you can create unlimited folders or subfolders as suitable for your website with CatFolders. Then, using the drag-and-drop feature to manage these files/folders in a clean, structured, and scalable library. 

Organize media files with CatFolders

Instead of scrolling endlessly through hundreds of uploads, you can sort files/folders by keywords, dates, or file type instantly. 

Search feature of CatFolders

When all your media files have been organized neatly, you can quickly give each file a caption. Because without folders, your WordPress media library is like a big shoebox where everything – images, PDFs, videos – is just tossed in together. When a visitor clicks โ€œnextโ€ on your gallery, WordPress will simply load the next file in its default order. 

Thus, CatFolders lets you check and optimize your file caption.

Add caption to media file

The CatFolders Document Gallery is an add-on that turns your folders into a professional, front-end gallery display. Perfect if you want to showcase PDFs, downloadable resources, portfolios, or shared company documents.

CatFolders Document Gallery supports two methods for creating a professional gallery for your WordPress website.

  • Using the CatFolders Document Gallery shortcode

You can head over to CatFolders, then see the section to create a Document Gallery. In here, you can select specific folders/subfolders to display on your gallery. For better visual, you can adjust settings like the number of columns, layout style, or metadata to show.

Create document gallery with shortcode feature

Copy and paste the shortcode. Now your selected folder is displayed as a dynamic gallery on the front end. Whenever you add or remove files from that folder, the gallery updates automatically.

The gallery on front-end by shortcode
  • Using the CatFolders Document Gallery Block with Gutenberg

With this method, you can build a document gallery directly from your post/page. It’s better for those who just want to show a stable gallery without changes.

You just need to search for the โ€œCatFolders Document Galleryโ€ block, and then you can configure your gallery with all the advanced features.

Create Gallery using Gutenberg Block

On your WordPress website, you can use the Code Snippets plugin to add a custom PHP snippet to create the custom column. 

Head over to add a new custom snippet to your website. Here is the hook for the caption column, which you can get and paste into the PHP Snippets section of the Code Snippets plugin:

//Add caption column
add_filter('catf_dg_columns',function($columns){
	array_splice($columns, -1, 0, 
		[
			[
				'label' => 	__( 'Caption', 'catfolders-document-gallery' ),
				'key' => 'caption',
			]
		]
	);
	
	return $columns;
},10);

//Display caption content into caption field
add_filter('catf_dg_columns_html',function($column, $file, $attributes){
	if ( 'caption' === $column['key']){
		$caption = get_post_field('post_excerpt', $file['document_id']);
		?>
		<td>
			<p class="cf-column-caption"><?php echo esc_html($caption); ?></p>
		</td>
		<?php
	}
	return $column;
},10,3);
Insert custom snippet to add custom column

Enable this snippet and see how it works.

Go back to your CatFolders Document Gallery, and youโ€™ll see your new Caption column in action. Itโ€™ll automatically pull in whatever you set in the media libraryโ€™s Caption field for each file.

display caption column in document gallery

Bonus: Create Smarter Document Galleries with Custom Columns

Tip 1: Add a File Description Column

Want to go further? You can display different data from your media file depending on the file type.

CatFolders has also provided a custom snippet to add a file description column to your document gallery. Letโ€™s check the example below to get the custom hooks.

You can get this snippet to display a file description column in your CatFolders Document Gallery. 

// The hook used to add a new column
add_filter( 'catf_dg_columns', 'catf_dg_add_column', 10, 1 );

/**
 * Add a new column
 *
 * @param array $columns An array used to define label and key of column
 * @return array
 */
function catf_dg_add_column( $columns ) {
    // Add label and key for new column here
    $columns[] = array(
        'label' => __( 'Description', 'catfolders-document-gallery' ),
        'key'   => 'description',
    );
    return $columns;
}

// The hook used to add content of column
add_filter( 'catf_dg_columns_html', 'catf_dg_add_column_html', 10, 3 );

/**
 * Add content of columns
 *
 * @param array $column Label and key of column
 * @param array $file Info of file
 * @param array $attr Attributes of table
 * @return array
 */
function catf_dg_add_column_html( $column, $file, $attr ) {
	$document_id = isset($file['document_id']) ? $file['document_id'] : "";
	
	if (empty($document_id)){
		return;
	}

    // Content of column
    if ( 'description' === $column['key'] ) {
        ?>
        <td>
            <div class=""><?php echo esc_html( get_post_field( 'post_content', $document_id ) ); ?></div>
        </td>
        <?php
    }

    return $column;
}

Move to the front-end to check how this snippet works.

Display File description in CatFolders Document Gallery

Tip 2: Add a Popularity (Click Counter) Column

CatFolders Document Gallery already comes with a built-in Counter column that automatically tracks how many times a file is clicked. Thatโ€™s super handy for monitoring engagement.

But sometimes, โ€œCounterโ€ feels a bit too technical. For a smoother user experience, you might want to rename it to something more intuitive – like Popularity. On the other hand, this phrase tells your visitors exactly what they want to know: which of your designs are trending, hot, and totally in demand. 

So weโ€™ll provide a custom snippet to change this name, you can get this:

add_filter( 'catf_dg_columns', function ( $columns ) {
	foreach($columns as $key => $column){
		if($column['key'] === 'counter'){
			$columns[$key]['label'] = __('Popularity', 'catfolders-document-gallery');
			break;
		}
	}
    return $columns;
}, 10);	

Now, instead of showing Counter, your gallery will display a Popularity column, making it clearer for end-users that this is a measure of file clicks and engagement.

add popularity column

Wrapping Up

CatFolders already transforms the WordPress Media Library into a clean, structured workspace. With the Document Gallery, you can showcase and manage files beautifully on the front end.

However, the real magic happens when you take it further, adding custom columns that display the exact information you need, from image dimensions to PDF page counts.

With just a few lines of code and CatFoldersโ€™ developer-friendly hooks, youโ€™ll turn your gallery into a powerful file management tool that saves time and boosts productivity.

Ready to take your WordPress file management to the next level? Try CatFolders today and start customizing your Document Gallery.

Thatโ€™s a wrap on adding custom columns to your CatFolders Document Gallery!

But wait, thereโ€™s more! If youโ€™d love to see these steps in action, weโ€™ve got you covered.
Watch more tutorials on our YouTube channel – packed with step-by-step guides, tips, and tricks to help you get the most out of CatFolders and WordPress.

Vicky Hoang
Vicky Hoang

Call me Vicky! I'm a blogger, a design lover, who is also a translator. I love exploring something new in the world. I like to share all things I have known with someone. That's why I'm here.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *