1. Home
  2. Knowledge Base
  3. Document Library Pro
  4. Advanced Usage

Displaying the publication date in the document library grid layout

By default, the Grid layout in Document Library Pro doesn’t include a built-in Date field (unlike the Table layout). However, you can easily display the publication date by adding a small code snippet that uses the available grid card hooks.

If you’re new to adding code snippets, see our short guide or request a quote from our customization service for assistance.

Code snippet

The following example outputs the document’s publish date on each grid card. It also respects your site’s date format set under Settings → General.

add_action( 'document_library_pro_grid_card_before_excerpt', function ( $document, $args, $post ) {
// Use the site’s date format from Settings > General
$date = get_the_date( get_option( 'date_format' ), $document->get_id() );
if ( $date ) {
echo '<div class="dlp-grid-date">' . esc_html( $date ) . '</div>';
}
}, 10, 3 );

Once added, refresh the page containing your document grid to see the date appear on each card.

Changing the position of the date

In the example above, the date is displayed before the excerpt. If you’d like to place it elsewhere (for example, below the image or above the title), you can switch to a different grid card hook.

Choose the hook that matches the position you want from the list of Grid card hooks, then use the same code inside that hook.

Styling the date

You can control the appearance of the date with custom CSS. For example:

.dlp-grid-date {
font-size: 0.9em;
color: #666;
margin-bottom: 0.5em;
}

Add this CSS to your theme or custom CSS area to adjust the size, color, or spacing.

Showing the file upload date instead

If you’d prefer to display the file’s upload date (from the WordPress Media Library) rather than the document’s publish date, you can adapt the snippet to fetch the attachment date instead. We also provide an example article.

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.