Giving away eBooks, white papers, and other valuable content is great way to grow your email list.
On Duane Smith’s website (one of my design partners), we recently added a Free Resources section with downloadable eBooks.
Building the form
With WPForms it’s easy to build a newsletter signup form. You can include a link to the PDF in the Confirmation Message shown after the form is submitted.
In this case, I want to use the same form with dozens of eBooks. I don’t want to create a separate form for each download.
Here’s the content creation workflow when adding a new eBook:
- Go to Pages > Add New
- Create a subpage of “Resources” with the title and summary of the eBook
- Include the “eBook Download” form we built with WPForms
- Upload the eBook in a custom metabox built with Advanced Custom Fields
I customized the Confirmation Message text to include a button to download the PDF uploaded to this page.
I’m appending our button to the end of the existing confirmation message because it’s the same for all downloads.
<?php
/**
* WPForms, include eBook download in confirmation message.
*
* @link https://www.billerickson.net/wordpress-ebook-optin-form/
*
* @param array $form_data
* @param array $form
*/
function be_wpforms_ebook_download( $message ) {
$attachment_id = get_post_meta( get_the_ID(), 'be_ebook', true );
if( !empty( $attachment_id ) )
$message .= '<div class="wp-block-button aligncenter"><a href="' . esc_url_raw( wp_get_attachment_url( $attachment_id ) ) . '" class="wp-block-button__link">Download Now</a></div>';
}
add_action( 'wpforms_frontend_confirmation_message', 'be_wpforms_ebook_download' );
I recommend you place this in a Core Functionality plugin so you don’t lose the functionality when changing themes.
Don’t let Google index your PDF
Even though we don’t link to the PDF directly on any page – visitors can only access the link by submitting the form – Google may still find it by digging through your uploads directory.
I recommend updating your robots.txt file to disallow indexing of PDF files. You can either edit it directly on the server via FTP, or use Yoast SEO’s file editor.
Go to SEO > Tools > File Editor. Click “Create robots.txt file” if you don’t see the box shown below. Add Disallow: /*.pdf
to the end of the file and click “Save changes to robots.txt”.
Daniel says
Thank you for these tutorials on WPForms! Very helpful!
Andy Globe says
Hi, thanks a lot for the guide.
I was wondering, does it slow down my site or my webhosting server when people download a 30mb pdf file? Would it be diffrent or better if I would link and provide the file on lets say google drive?
All the best to you and thanks a lot
Bill Erickson says
That’s a better question for your hosting provider. Most high quality hosts will have a Content Delivery Network like Cloudflare on the frontend serving assets.