1. Document Library Pro
  2. FAQ

Can I add custom fields and taxonomies to the document library?

Document Library Pro comes with all the standard WordPress fields, such as the document title, content, excerpt, featured image, author and date. It also comes with two custom taxonomies: document categories and document tags. It generates other information automatically, such as the file size and type.

You can use any WordPress custom fields or custom taxonomy plugin to create additional fields for your document library, and display them using the table or grid layout. This article explains how to do this.

Creating custom fields

Custom fields are for storing unique information about each document. Only use custom fields for data that you do not need to group or filter by, for example a document reference number, filename, version number or revision date.

  1. Create as many custom fields as you like using your chosen plugin, and enable it for the dlp_document post type. This will add it to the bottom of the Add/Edit Document page.
  2. Go to the Add/Edit Document page and add information to the custom field for each document.

Creating custom taxonomies

Custom taxonomies provide extra ways of grouping your documents. For example, if you want to store the publisher or year for each document, so that users can filter by publisher, language or year, then you should add these as custom taxonomies.

  1. Create as many custom taxonomies as you like using your chosen plugin, and enable it for the dlp_document post type. This will add it to the right hand side of the Add/Edit Document page.
  2. Go to the Add/Edit Document page and tag your documents with the relevant taxonomy terms.

Once created, your custom taxonomies will appear in the left of the WordPress admin under Documents menu item. You can add/edit/delete/restructure your taxonomies centrally from there.

You can use any plugin that allows you to create custom fields or taxonomies. Choose one based on which features you need. We recommend the following free plugins:

Display custom fields with the table layout

Display the custom field as a column in the document library table.

Display custom taxonomies with the table layout

Display the custom taxonomy as a column in the document library table.

You can also list each taxonomy in a filter dropdown above the document library so that people can find documents more quickly.

Display custom fields with the grid layout

Display the custom field on the document grid cards using one of the available grid card hooks.

The example below illustrates adding this data below the title and before the excerpt. Use a different grid card hook to change the position.

The key of the custom field is custom_field and should be replaced with the key of the custom field you want to display.

add_action( 'document_library_pro_grid_card_before_excerpt', function ( $document, $args, $post ) {
    ?>
    <div class="dlp-grid-custom-field">
        <span class="dlp-grid-custom-field-title"><?php_e( 'Custom Field: ', 'text-domain' ); ?></span>
        <?php echo get_post_meta( $document->get_id(), 'custom_field', true ); ?>
    </div>
    <?php
} );

Display custom taxonomies with the grid layout

Display a list of custom taxonomy terms on the document grid cards using one of the available grid card hooks.

The example below illustrates adding this data below the title and before the excerpt. Use a different grid card hook to change the position.

The id of the custom taxonomy is custom_taxonomy and should be replaced with the id of the custom taxonomy you want to display.

add_action( 'document_library_pro_grid_card_before_excerpt', function ( $document, $args, $post ) {
    ?>
    <div class="dlp-grid-custom-tax">
        <?php echo get_the_term_list( $document->get_id(), 'custom_taxonomy' ); ?>
    </div>
    <?php
} );

Displaying custom fields and taxonomies on the single document page

The instructions above tell you how to create custom fields and taxonomies, and display them on the main document library pages. With some custom coding, you can also display them on the individual page for each document.

If you have already created a custom single document page template then you should add code to output your custom fields and taxonomies there. If you're not using a custom template then you can adapt the code snippets below in order to add custom fields and taxonomies.

Custom Fields

add_action( 'document_library_pro_single_document_details_list_after', function () {
    ?>
    <div class="dlp-document-info-custom-field">
        <span class="dlp-document-info-title"><?php_e( 'Custom Field: ', 'text-domain' ); ?></span>
        <?php echo get_post_meta( get_the_ID(), 'custom_field', true ); ?>
    </div>
    <?php
} );

Custom Taxonomies

add_action( 'document_library_pro_single_document_details_list_after', function () {
    ?>
    <div class="dlp-document-info-custom-tax">
        <span class="dlp-document-info-title"><?php_e( 'Custom Taxonomy: ', 'text-domain' ); ?></span>
        <?php echo get_the_term_list( get_the_ID(), 'custom_taxonomy' ); ?>
    </div>
    <?php
} );

Related Articles

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