You may have noticed I’ve added subscribe widgets at the end of every post, right below the related articles. It’s really simple to do, and comes built-in with the Jetpack WordPress Plugin.
First, make sure you’re using a child theme so you’re not changing the core code of your theme, as your changes will be lost on updates. You can read about creating a child theme here at the WordPress Codex.
1. Register New Sidebar
First, add this to your functions.php
file. It will register a new sidebar called Subscribe In Page.
register_sidebar( array( 'name' => 'Subscribe in page', 'id' => 'subscribe-in-page', 'before_widget' => '<div id="subscribe">', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>' ) );
2. Call Our New Sidebar
Now, in your WordPress loop, find something like <?php the_content(); ?>. Here’s what my the_contenet()
call looks like:
<div class="entry-content" itemprop="mainContentOfPage"> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links-next-prev">', 'after' => '</div>', 'nextpagelink' => '<button class="next-page-nav">' . __( 'Next page →', 'independent_publisher' ) . '</button>', 'previouspagelink' => '<button class="previous-page-nav">' . __( '← Previous page', 'independent_publisher' ) . '</button>', 'next_or_number' => 'next' ) ); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'independent_publisher' ), 'after' => '</div>' ) ); ?> </div> <!-- .entry-content -->
Notice there’s a couple functions after the_content(), this is normal and will vary from theme to theme. Any plugins you’ve got set to appear below your post will be shown, and then the subscription form will be shown.
4. Add Your Jetpack Subscribe Widget
Just like adding a normal widget. Go to Appearances, and then Widgets. You should see an area titled Subscribe In Page. Drag the Blog Subscriptions (JetPack) widget into the Subscribe In Page sidebar area. Configure it, save it.
5. Add The Sidebar To The Theme
To add the Jetpack subscription form, add <?php dynamic_sidebar( ‘subscribe-in-page’ ); ?>, which calls our custom sidebar, to your loop. It should go somewhere under the_content()
if you want it to show at the end of the post. If you want it at the beginning, add <?php dynamic_sidebar( ‘subscribe-in-page’ ); ?> before the_content()
.
You’re Done!
And that’s really all there is to adding a subscribe form to the end of each post. You can also add the same subscribe form in the sidebar, like I have at longren.org. As a note, the Jetpack plugin is packed full of functionality. Chances are good that you’ll find more Jetpack modules to use, other than the Subscriptions module.
