The Internet allows us to chat, exchange, search for news, share experiences, and download documents, gadgets, applications, etc. So if you have a WordPress website and want to share documents with users, creating a download button using custom fields is not a bad idea - it looks beautiful, professional, and not difficult to create at all.

In this article, we’re going to show you how to create a download button using custom fields with Meta Box plugin, and then display this button on the front end in two ways: adding code to the theme’s file and using a shortcode. But first, let’s take a quick look at when you should create and use the download buttons!

 

The Applications of Download Buttons

The download buttons can be used for many situations, but it works best in these kinds of site:

  • Business websites: download profiles, catalogs, decisions, annual reports, ... of the company.
  • Real estate websites: download price lists, project brochures, information about apartments / lands for sale.
  • Travel websites: download trip brochures.
  • Law websites: download law documents.
  • Blogs: download documents that bloggers share.

This is an example of how we use the download button on our Meta Box pricing page.

Use the Download button on the product page of Meta Box

The download buttons are really useful, so how can we add them to our site? Let’s see!

Before Getting Started

To create download buttons by custom fields, we need the following tools:

  • Core plugin Meta Box: a framework that helps us create custom fields, custom meta boxes easily and quickly. It’s free and available on wordpress.org.
  • Meta Box Builder: a premium extension of Meta Box that provides you a UI to create custom fields right on the back end.

If you don’t want to use the premium extension Meta Box Builder, you can still manually code to create custom fields. Or you can use the free Online Generator tool of Meta Box to save time and money. This tool comes up with an intuitive UI for creating custom fields. Once you finish creating fields, it will automatically generate code, and then you can add this code to the functions.php file. Get more details on how to use this tool here.

Besides, I use eStar theme and create a child theme. This multipurpose theme is free and very lightweight, you can download it here.

Once you finished installing and activating the plugins, follow these steps:

Step 1: Create the Download Button Using Custom Fields

First, go to Meta Box > Custom Fields > Add New. After that, click the Add Field button, search and choose the File Advanced field type. Next, enter the field ID and Label. Here’s what I do:

Create the Download Button Using Custom Fields

To display custom fields in all posts on the website, go to Settings tab, and choose Posts in the Show for section. Then, choose the Post types as Post (you can choose other post types such as page or a custom post type).

Set up where the custom fields will be display in the settings of Meta Box plugin

And don’t forget to click Publish.

Step 2: Upload the Documents

Go to any post type that you want to display the download button. In the WordPress editor, the custom field that we’ve created displays as follows:

the custom field that we’ve created displays

Upload the document that you want to share with readers by clicking Add Media. This is the document that I’ve uploaded:

The document is inserted to the custom fields

Now we’ve finished uploading a document. Still, readers can’t see the download button on the front end, so let’s do it in step 3.

Step 3: Display the Download Button on the Front End

This can be done using two methods: adding code to the theme or using a shortcode. The first method is suitable when you just need to display the download button in only one position on all pages. Meanwhile, the second method is faster and more convenient if you want to insert the download buttons in different positions on different pages.

Method 1: Display the Download Button by Adding Code to the Theme

For example, I want to display the download button at the end of all posts.

Display the Download Button in the end of the post content

To do so, add this code to the functions.php file of the child theme:

add_action( 'estar_entry_footer_before', 'estar_child_add_link' );
function estar_child_add_link() {
	?>
	<div class="document_link_download abc">
		<?php
		$files = rwmb_meta( 'file_download' );
		foreach ( $files as $file ) : ?>
			
		<a class="document_link" href="<?php echo $file['url'] ?>" target="_blank">
			<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-download"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
			<?php esc_html_e( 'Download document', 'estar' ) ?>		
		</a>

		<?php endforeach ?>
	</div>
	<?php
}

Explanation:

  • 'file_download' is the ID of the custom field for documents uploading that we’ve created in step 1.
  • 'estar' is the theme that I’m using.
  • add_action( 'estar_entry_footer_before', 'estar_child_add_link' );function estar_child_add_link() { ?> is the code to specify the location in which you want to display the download button. In this case, I display the download button in the 'estar_entry_footer_before' hook of eStar theme. This hook is created right on the tags list. You can refer to this hook here (line 42).

And this is the result:

The download button is displayed on the front end of WordPress website

Done! We’ve finished displaying the download button in a fixed position on all pages by adding code to the theme. But if this method doesn’t fit your requirements, try the second method below.

Method 2: Display the Download Button Using a Shortcode

First, add this code to the functions.php to create the shortcode:

add_shortcode( 'estar_button_download', 'estar_button_download');
function estar_button_download() {
	ob_start();
	?>
	<div class="document_link_download abc">
		<?php
		$files = rwmb_meta( 'file_download' );
		foreach ( $files as $file ) : ?>
			
		<a class="document_link" href="<?php echo $file['url'] ?>" target="_blank">
			<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-download"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
			<?php esc_html_e( 'Download document', 'estar' ) ?>		
		</a>

		<?php endforeach ?>
	</div>
	<?php
	return ob_get_clean();
}

Explanation:

estar_button_download is the shortcode for the download button (you can name it whatever you want). From now on, you just need to insert this shortcode in the desired positions such as posts, pages, widgets.

For example, I insert the [estar_button_download] shortcode in the content of a post as follows:

Display the Download Button Using a Shortcode

Or I can add the shortcode to a widget like this:

Insert the shortcode into a widget in WordPress
Add the shortcode to a widget

Display the download button in the sidebar of WordPress website

 

Also, you can display the download button in other positions depending on your needs so that the buttons look eye-catching and appealing.

Last Words

What do you think? Using the download buttons is more effective and professional than inserting an ugly long hyperlink, right? In addition to creating the download button using custom fields, Meta Box plugin has many other interesting applications that we will seamlessly update in the upcoming tutorials.

If you have any questions or ideas about using Meta Box plugin, feel free to share them with us in the comment section or in the Meta Box users group here!

 

Other case studies you might be interested in

  1. Create A Dynamic Landing Page in WordPress Using Custom Field
  2. Create a Filter to Find Hotels by Location
  3. Create an OTA Website Like Booking.com with Meta Box Plugin - P1: Create a Page to Introduce Hotel Rooms
  4. Create an OTA Website Like Booking.com with Meta Box Plugin - P2: Create Filters on the Archive Page
  5. Create an OTA Website Like Booking.com with Meta Box Plugin - P3: Create Filters for Single Hotel Pages
  6. Create Dynamic Favicon in WordPress using Meta Box plugin
  7. Create Posts Series in WordPress Using Meta Box
  8. Display a User List On the Frontend with Meta Box
  9. Display The Latest Products Section - P2 - Using Meta Box and Elementor
  10. Display The Latest Products Section - P3 - Using Meta Box And Oxygen
  11. How to Add Custom Fields to Display Banners using Meta Box Plugin
  12. How to Add Guest Authors and Guest Posts - Using Meta Box
  13. How to Add Related Posts to WordPress Using Meta Box
  14. How to Build a Hotel Booking Website Using Meta Box - P1
  15. How to Build a Hotel Booking Website Using Meta Box - P2 - Booking Page in Backend
  16. How to Build a Hotel Booking Website Using Meta Box - P4 - Booking Management Page
  17. How to Build a Hotel Booking Website Using Meta Box – P3 – Booking Page for Customer
  18. How to Create a Classified Ads Website using Meta Box
  19. How to create a FAQs page - P5 - Using Meta Box and Breakdance
  20. How to Create a Product Page - P2 - Using Meta Box and Oxygen
  21. How to Create a Product Page - P3 - Using Meta Box and Bricks
  22. How to Create a Product Page - P4 - Using Meta Box and Elementor
  23. How to Create a Product Page - P5 - Using Meta Box and Gutenberg
  24. How to Create a Product Page - P6 -Using Meta Box and Breakdance
  25. How to Create a Product Page - P7 - Using Meta Box + Kadence
  26. How to Create a Product Page - P8 - Using Meta Box and Brizy
  27. How to Create a Product Page using Meta Box Plugin
  28. How to Create a Recipe - P2 - Using Meta Box and Oxygen
  29. How to Create a Recipe - P3 - Using Meta Box and Elementor
  30. How to Create a Recipe - P4 - Using Meta Box and Bricks
  31. How to Create a Recipe - P5 - Using Meta Box and Zion
  32. How to Create a Recipe - P6 - Using Meta Box and Brizy
  33. How to Create a Recipe - P7 - Using Meta Box and Breakdance
  34. How to Create a Recipe with Meta Box Plugin
  35. How to Create a Simple Listing - P2 - Using Meta Box and Bricks
  36. How to Create a Team Members Page - P1- Using Meta Box and Elementor
  37. How to Create a Team Members Page - P2 - Using Meta Box and Oxygen
  38. How to Create a Team Members Page - P3 - Using Meta Box and Bricks
  39. How to Create a Team Members Page - P4 - Just Meta Box
  40. How to Create a Team Members Page - P6 - using Meta Box and Breakdance
  41. How to Create a Video Gallery Page - P2 - Using Meta Box + Bricks
  42. How to Create a Video Gallery Page - P3 - Using Meta Box and Breakdance
  43. How to Create a Video Gallery Page - P4 - Using Meta Box + Elementor
  44. How to Create a Video Gallery Page - P5 - Using MB Views
  45. How to Create a Video Gallery Page Using Meta Box + Oxygen
  46. How to Create ACF Flexible Content Field with Meta Box
  47. How to Create an Auto-Updated Cheat Sheet in WordPress
  48. How to Create an FAQs Page - P1 - Using Meta Box and Elementor
  49. How to create an FAQs page - P2 - Using Meta Box and Oxygen
  50. How to create an FAQs page - P4 - Using Meta Box and Bricks
  51. How to Create an FAQs Page -P3- Using Meta Box
  52. How to Create Buttons with Dynamic Link using Custom Fields
  53. How to Create Category Thumbnails & Featured Images Using Custom Fields
  54. How to Create Download and Preview Buttons - P1 - Using Meta Box and Bricks
  55. How to Create Download and Preview Buttons - P2 - Using Meta Box and Oxygen
  56. How to Create Download Buttons Using Custom Fields with Meta Box Plugin
  57. How to Create Menus for Restaurants - P1 - Using Meta Box and Elementor
  58. How to Create Menus for Restaurants - P2- Using Meta Box and Bricks
  59. How to Create Online Admission Form for School or University
  60. How to Create Online Reservation Form for Restaurants using Meta Box
  61. How to Create Relationships - P1 - Using Meta Box and Oxygen
  62. How to Create Relationships - P2 - Using Meta Box and Bricks
  63. How to Create Relationships - P3 - Using MB Views
  64. How to Create Taxonomy Thumbnails & Featured Images - P2 - Using Meta Box and Oxygen
  65. How to Display Images from Cloneable Fields - P1 - with Gutenberg
  66. How to Display Images from Cloneable Fields - P2 - with Oxygen
  67. How to Display Images from Cloneable Fields - P3 - with Elementor
  68. How to Display Images from Cloneable Fields - P4 - with Bricks
  69. How to Display Opening Hours for Restaurants - P1 - Using Meta Box + Gutenberg
  70. How to Display Opening Hours for Restaurants - P2 - Using Meta Box and Oxygen
  71. How to Display Product Variations - P1 - Using Meta Box and Gutenberg
  72. How to Display Product Variations - P2 - Using Meta Box and Oxygen
  73. How to Display Product Variations - P3 - Using Meta Box and Bricks
  74. How to Display The Latest Products - P5 - Using Meta Box and Bricks
  75. How to Display the Latest Products - P6 - using Meta Box and Breakdance
  76. How to Display the Latest Products - P7 - Using Meta Box + Kadence
  77. How to Display the Latest Products Section - P4 - Using Meta Box + Zion
  78. How to Display the Most Viewed Posts - P1 - using MB Views
  79. How to Display the Most Viewed Posts - P2 - using Meta Box and Oxygen
  80. How to Filter Posts by Custom Fields - P2 - using Meta Box and FacetWP
  81. How to Manually Reorder Posts with Meta Box
  82. How to Show Featured Restaurants on Homepage - P1 - Meta Box + Elementor + WP Grid Builder
  83. How to Show Posts With a Specific Criteria - P3 - Using MB Views
  84. How to Show Posts with Specific Criteria - P1 - Using Meta Box and Bricks
  85. How to Show Posts with Specific Criteria - P2 - Using Meta Box and Oxygen
  86. How to Show Posts with Specific Criteria - P4 - Using Meta Box + Breakdance
  87. How to Show Posts with Specific Criteria - P5 - Using Meta Box and Elementor
  88. How to Show the Featured Restaurants - P3 - using Meta Box and Oxygen
  89. How to Show the Featured Restaurants - P4 - Using MB Views
  90. How to Show the Featured Restaurants - P5 - Using Meta Box and Elementor
  91. How to Show the Featured Restaurants - P6 - Using Meta Box and Zion
  92. How to Show the Featured Restaurants Section - P2 - Using Meta Box and Bricks
  93. How to Use Custom HTML Field to Output Beautiful Texts or Output Custom CSS

2 thoughts on “How to Create Download Buttons Using Custom Fields with Meta Box Plugin

  1. What is the best way to add an email form to this method? Basically, I'd like to be able to capture the viewer's information before sending them to the download link.

    Is it best to create a user role for this and effectively log them in, or is there a simple way to have an email field popup that must be completed before the download is started?

Leave a Reply

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