Add a Jetpack Subscription Form Below Your Blog Post

How to add a Jetpack subscription form below your blog posts

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:

A screenshot of a blog post, with the Jetpack subscription widget appearing below the post

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. πŸ™‚

Have you added an opt-in form below your posts yet?

Photo of Ashley
I'm a 30-something California girl living in England (I fell in love with a Brit!). My three great passions are: books, coding, and fitness. more »

Don't miss my next post!

Sign up to get my blog posts sent directly to your inbox (plus exclusive store discounts!).

You might like these

32 comments

  1. I really can’t believeβ€”you take “helping bloggers” to another level, Ashley πŸ˜€

    1. You just need me to install the plugins for you. πŸ™‚ I’ve added it and it should now appear in your “Plugins” list.

  2. 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. πŸ™‚

    Dragana recently posted: March 2015 – Monthly Rewind
  3. 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?

    1. I have the custom plugin already installed. πŸ™‚ Just look for Jetpack After Post in the plugin list and activate that.

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

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

      // If we're not on a single post page, bail.

      Try adding that.

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

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

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

  8. 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?

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

Recent Posts

    Random Posts