Boost Email Opt-in form by Wpforms category

Email opt-in forms in WordPress using WPForms and Advanced Custom Fields.

For bloggers and publishers, email opt-in with a vital strategy to grow their subscriber base and engage readers. A well-targeted email opt-in form can significantly improve subscription rates, making it essential to tailor these forms based on the content category of each post.

Instead of creating separate opt-in forms for each category, a more efficient method involves using a single email opt-in form and dynamically customizing its title and description based on the category metadata. This article will guide you through the process of setting up category-specific email opt-in forms using WPForms and Advanced Custom Fields (ACF).

1200x628 Increase Your Email Opt in Form Sign ups Featured Image 1

we could create a different form for different category, the basic approach is to build a single form and use category metadata to overcome the default title and description for each categories.

Set Up a Default Form

To begin, go to WPForms > Add New and create a new newsletter signup form. This form will serve as the base template for all categories on your site. Define a standard title and description that will be universally applicable. For example:

Email Opt In Forms Capturing Newsletter Subscribers Facebook

This default setup ensures that even if a category-specific title or description is not provided, the form remains functional and inviting.

Add Category-Specific Overrides

Advanced Custom Fields is a powerful plugin that allows you to add custom fields to your WordPress site. Install and activate ACF from your WordPress dashboard. Once activated, you can create custom fields that will appear on the Edit Category screen.

optin metabox 1536x529 1

Create Custom Fields for Categories

Navigate to Custom Fields > Add New to create a new field group. Name this group something like “Category Optin Settings.” Within this group, add two fields:

  1. Field Label: Email Opt-in Title
    Field Name: Email opt-in_title
    Field Type: Text
  2. Field Label: Emial Opt-in Description
    Field Name: Email opt-in_description
    Field Type: Textarea

Set the location rules to display this field group if the taxonomy is equal to “category.” This will ensure that these fields appear on the Edit Category screen, allowing you to set a unique title and description for each category.

Update Your Theme to Display Custom Fields

To make your custom fields functional, you need to update your theme’s code to fetch and display the custom optin title and description. Add the following code to your theme’s functions.php file:

/**
 * Customize opt-in title/description by category
 * @link https://noomaan.com/category-specific-email-optin-with-wpforms/‎
 *
 * @param array $form_data
 * @return array
 */
function be_wpforms_category_optin( $form_data ) {
	if( 123 != $form_data['id'] )
		return $form_data;
	$term_id = false;
	if( is_category() )
		$term_id = get_queried_object_id();
	elseif( is_single() )
		$term_id = ea_first_term( [ 'field' => 'term_id' ] );
	if( ! $term_id )
		return $form_data;
	$title = get_term_meta( $term_id, 'be_optin_title', true );
	if( !empty( $title ) )
		$form_data['settings']['form_title'] = $title;
	$description = get_term_meta( $term_id, 'be_optin_description', true );
	if( !empty( $description ) )
		$form_data['settings']['form_desc'] = $description;
	return $form_data;
}
add_filter( 'wpforms_frontend_form_data', 'be_wpforms_category_optin' );

This code checks the category of the current post and retrieves the custom optin title and description if they exist. It then uses WordPress filters to override the default title and description of your WPForms optin form.

Test and Refine

After implementing the above steps, it’s crucial to test your setup. Create a few posts in different categories and ensure that the optin form displays the correct title and description for each category. Adjust the custom field values on the Edit Category screen and verify that the changes are reflected on the frontend.

Benefits of Category-Specific Optin Forms

By customizing your email opt-in forms based on the content category, you create a more personalized experience for your readers. This approach has several benefits:

  1. Increased Relevance: Readers are more likely to subscribe if the optin form is tailored to the content they are interested in.
  2. Higher Engagement: Personalized messages can boost engagement and make your audience feel valued.
  3. Improved Conversion Rates: A targeted optin form can lead to higher subscription rates compared to a generic form.

Conclusion

Optimizing your email opt-in forms by category is a powerful strategy to enhance user experience and boost your email subscriptions. By leveraging WPForms and Advanced Custom Fields, you can easily implement category-specific titles and descriptions, creating a more personalized and effective optin process. Follow the steps outlined in this guide to set up your customized opt-in forms and watch your subscriber list grow.

Leave a Reply

noomaan_wordpress_developer-favicon-865f

Noman Ali

Noman Ali is web developer at Dev House, a custom software development agency focusing on high performance sites for web applications.

Ready to upgrade your website?

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

Other articles in this series

How to Seamlessly Add Facebook Comments in WordPress

Learn how to add Facebook comments in WordPress website to boost social engagement and simplify the commenting experience for your visitors. Step-by-step guide included.…

How to add Gutenberg Shortcodes in WordPress: A Comprehensive Guide

Unlock the power of Gutenberg shortcodes in WordPress to create dynamic, interactive, and SEO-friendly content. Learn how to use, customize, and optimize shortcodes for…

Learn Gutenberg Theme Development

Learn how to master Gutenberg theme development for WordPress with our comprehensive guide. Discover essential techniques, best practices, and advanced tips to create visually…

4 Easy Steps to Remove Core WordPress Blocks

Learn how to remove core WordPress blocks and improve your theme's design and functionality. Our guide provides detailed steps for unregistering unnecessary blocks.

Recommended Freeelancing Services