Do you want to insert your email subscription form into WordPress posts automatically? Doing this increases your email subscription rate, and this post teaches you how to do that.
Step 1: Install the Code Snippets Plugin
As I mentioned in the introduction, the recommended way to add codes to functions.php is via the Code Snippets Plugin. If you have not installed this plugin before, follow the steps below to install the plugin.
On the other hand, if you have already installed the plugin, feel free to jump to the next section of this article.
- Sign in to your WordPress dashboard with your admin account. Then, hover over Plugins and select Add New.
- When the Add Plugins page opens, enter Code Snippets in the search box (top right). Then, click Install Now to the top right of the Code Snippets plugin.
The plugin will install. After it installs, click Activate. Then, proceed to the next step of this guide.
Step 2: Add a New Code in Code Snippets
As I mentioned in the introduction, you need to automatically add a code to insert email subscriptions in WordPress posts. Follow the steps below to add the custom code with the Code Snippets plugin.
- Sign in to your WordPress dashboard with your admin account. Then, hover over Snippets and select Add New.
- When the Add New Snippet window opens, give the snippet a name (1) – see the screenshot beneath the code block below.
Then, copy the code below to the code area (2). Finally, click Activate to save and activate the code on the top right of the window.
return prefix_insert_after_paragraph( $email_subscription_code, 7, $content );
Finally, before you move on, copy the code for your email subscription form to the part of the code I boldened – add code here.
//Insert email subscription form after 7th paragraph add_filter( 'the_content', 'prefix_insert_post_email_subscription' ); function prefix_insert_post_email_subscription( $content ) { $email_subscription_code = '<center>add code here </br></center>'; if ( is_single() && !is_admin() ) { return prefix_insert_after_paragraph( $email_subscription_code, 7, $content ); } return $content; } // Parent Function function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '</p>'; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $insertion; } } return implode( '', $paragraphs ); }
Conclusion
I always wanted to insert my email subscription form within my WordPress posts automatically. However, I did not know how to do it.
When I eventually found out how to do this, my email subscription skyrocketed! Based on the level of success I had with it, I decided to share how I did it.
So, there you have it – the steps to insert an email subscription form in WordPress posts automatically! I hope you found the guide easy to follow.
I also hope that you’ve successfully inserted your email subscription form into your articles. If you did, click on “Yes” beside the “Was this page helpful” question below.
You may also express your thoughts and opinions by using the “Leave a Comment” form at the bottom of this page.
Finally, visit our WordPress & Websites How-Tos page for more WordPress and general website guides.