1. Home
  2. Document Library Pro
  3. Advanced Usage

Code snippet: Hide the download button for certain documents

People normally use the Document Library Pro plugin to display documents with a link to an individual page for each document and/or a button to download the document. However, there are situations where you may wish to hide the download button for documents where you have not uploaded a file. Normally, if a document does not have a file attached then the download button will link to the single document page - however, you may not want this.

The following code snippet will hide the download button in the link column for documents where the Document Link field is set to "None":

 add_filter( 'document_library_pro_download_button_should_display', function( $display, $obj, $link_text, $link_style, $link_destination ) {
	$link_type = get_post_meta( get_the_ID(), '_dlp_document_link_type', true );
	if ( ! empty( $link_type ) && $link_type !== 'none') {
		return true;
	}
    return false;
}, 10, 5 );

If you don't know how to add code snippets to your site then you should ask your developer, or post a job on Codeable to find an experienced developer who can do it for you.

We've partnered with Codeable to provide our customers with expert help if required.

Related Articles

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