How to Create an eBook Optin Form in WordPress

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:

  1. Go to Pages > Add New
  2. Create a subpage of “Resources” with the title and summary of the eBook
  3. Include the “eBook Download” form we built with WPForms
  4. 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”.

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk

Reader Interactions

Comments are closed. Continue the conversation with me on Twitter: @billerickson

Comments

  1. 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.