Hi Ashley! Same person who asked about the subscription box under posts in WP. I just have a follow up question – do you know how to use the Jetpack subscription widget under posts? I’ve hunted for a shortcode or something, but the only one I’ve found can’t be edited, so I was wondering if you had any ideas. Thank you π
For those of you who haven’t seen it, here’s a link to my post on how to add an opt-in box below your posts. That works for platforms OTHER than Jetpack.
It’s definitely possible to add a Jetpack subscription form below your post. The easiest way to do this is by actually displaying the subscriber widget below each post. It’s pretty easy to do this with a simple plugin.
Here’s a screenshot of the final product from my test site, which is using the Twenty Fifteen theme:
Creating a custom plugin
This plugin is so quick and easy that I’m just going to paste the whole thing for you here:
<?php /* Plugin Name: Jetpack After Post Plugin URI: https://www.nosegraze.com/jetpack-subscription-below-blog-post/ Description: Adds a Jetpack subscription widget after each blog post. Version: 1.0 Author: Ashley Author URI: https://www.nosegraze.com License: GPL2 */ function jetpack_after_post( $content ) { global $post; $post_type = get_post_type( $post ); // If we're not on a blog post, bail. if ( $post_type != 'post' ) { return $content; } // If we're not on a single post page, bail. // You can remove this if you want the form to appear on your homepage too. if ( ! is_single() ) { return $content; } ob_start(); // Display the Jetpack widget. $instance = array(); $args = array( 'before_widget' => '', 'after_widget' => '', ); the_widget( 'Jetpack_Subscriptions_Widget', $instance, $args ); return $content . ob_get_clean(); } add_filter( 'the_content', 'jetpack_after_post', 500 );
You’ll want to copy and paste this into a new PHP file in a text editor, then save it inside a new folder. I created a new folder called jetpack-after-post and saved my file inside there and called it jetpack-after-post.php
The comments at the top are to tell WordPress that this is a custom plugin. We give the name, URL, description, author, etc. of our plugin.
Then, what we do is filter the post content. This means we’re adding extra stuff either before or after the post content. In our case, we’re adding something after.
Only add the form to blog posts
If you look at this segment, we’re only adding this content to blog posts:
global $post; $post_type = get_post_type( $post ); // If we're not on a blog post, bail. if ( $post_type != 'post' ) { return $content; }
If we’re not on a blog post, we return the normal content straight away. So, as an example, if we didn’t have that block of code in, then this form would also appear on pages. You probably don’t want that.
Display the Jetpack widget
Then the next portion of code is displaying the widget with the default settings.
You can also see in my code that I added the form AFTER the post content. See this:
return $content . ob_get_clean();
$content
is the content of the blog post. We return that and then the widget after it. Had I done it the other way around, the form would appear first:
return ob_get_clean() . $content;
Change the settings
With this code, the plugin is going to use all the defaults for the widget. That means the title will be “Subscribe to Blog via Email” and you’ll get the default message. But you can change these by editing the $instance
variable. By default, I haven’t changed any settings, as you can see by this line:
$instance = array();
But here’s an example of how you would change the widget title:
$instance = array( 'title' => 'Subscribe' );
And if you also wanted to change the subscribe text:
$instance = array( 'title' => 'Subscribe', 'subscribe_text' => 'By subscribing to my blog, you\'ll receive every new post in your inbox. Awesome!' );
How to install this plugin
I’ve packaged this up into a neat little plugin for you, if you’d rather just download it:
You can install it by downloading and saving this zip file, then in WordPress go to Plugins » Add New » Upload and upload the zip file there.
If you’d rather use your own modified version based on the code, just make sure you’ve saved your plugin inside its own folder. Then then zip it up into a .zip file, and install it the same way. π
Thank you so much for this plugin! I was reading the post thinking “OMG how do I find the PHP file” and that made my head hurt. I’m so glad you shared.
Haha, you’re very welcome. π
I really can’t believeβyou take “helping bloggers” to another level, Ashley π
I do my best. π
I’m going to say the most stupid thing :(…i can’t find “add new plugin” :(:( When i go to plugins only appears the ones to activate and desactivate :'(
You just need me to install the plugins for you. π I’ve added it and it should now appear in your “Plugins” list.
Thank you! I’ll go check π
I haven’t added opt-in form below my posts because I think there is enough clutter there already. I am thinking about switching recommended posts widget with this one when I do a spring cleaning on the blog. Then this awesome tutorial of yours will definitely be handy. π
I love this! I’m going to put it in my to-do list to add to my posts. Thanks for the plugin, I’m nervous about adding something on my own π
You’re welcome. π I hope it works out for you!
Does this only work with JetPack for blog post subscription, or is it possible to use it with something like a mail chimp sign up at the bottom of the posts?
Yep, I did a more general post on how to add an opt-in box below your posts.
There are a variety of plugins you can use for other opt-in methods (MailChimp, Feedburner, etc.) or you can code it yourself.
Thank you for this! So awesome and so easy to add π
I’m having trouble finding the add new on the plug in page…I’m probably overlooking it haha. Thanks for sharing π
I have the custom plugin already installed. π Just look for Jetpack After Post in the plugin list and activate that.
thanx ….for this information
Thanks for this helpful post. If you please add some css with this plugin then it will be more stunning.
Hi Ashley!
Great plugin! thank you for sharing. You are awesome!
I have a question about whether you can show the ‘subscribe’ module at the bottom of a post but NOT at the bottom of each post when viewed from the typical blog page (page summarising all the blog posts). I.e.,
Blog title 1 – AAAAA
*Subscribe*
Blog title 3 – CCCC
*Subscribe*
to change to
Blog title 1 – AAAAA
Blog title 2 – BBBBB
Blog title 3 – CCCC
Hi James,
I added a new bit of code to the post you may want to look at. Look for this line and the new segment below it:
Try adding that.
I downloaded the plugin, installed it but how i put it on my post. Please explain
Hi there,
Exactly, I want it for my site. I’ve already installed and activate the plugin that you preferred to free download. But I can’t understand how to manage it. Also I can’t see anything on my widget and post. I’ve little bit idea about jetpack.
I just want it exactly that you showed top of the page on your site. Can you please help me to do that as like as you did. Actually, it’s badly needed for me.
Thank you.
Thanks for this nice and effective tips of how to add jetpack subscription form at the bottom of the post. Literally, you have just made my day. I searched a lot for this tips but at last i got it. Email list building has enormous importance on blog success and now definitely i am going to make that with this amazing jetpack subscription code tips. Thanks Once again.
Exactly what I needed and worked perfectly – thanks a million
I’ve implemented this example on my blog. Thank you for being wonderful and this awesome post.
Thanks so much for this post, it was really helpful and easy to use!
Loving this plugin. Quick question. How do I get rid of the “join x other subscribers’ text in the plugin? I was able to adjust the other text but im unsure about this. Thanks!
I know this is a really long time after the original post, but I’m wanting to just insert the subscribe box to one (sticky) post on my blog. Is that do-able. Easily?
Well done… Great Job … Thanks for this work around I’ve been looking for a way to add jetpack sub form under posts for a long while now.
thanks it worked like magic.. you are a life safer
Thank you so much! Just downloaded/activated it. Hoping it works the way I envision π
Thanks Ashley for this!
Am so so glad i came across this your post. Would love to meet you someday