|About two weeks ago, the WordPress.com team released a wonderful new tool called the Follow Button to all theirs WordPress.com users. This button is floating in the bottom-right corner of a blogs and let readers subscribing, by email, to the blog’s publications. Each time a new blog post is published, they receive an update in their inbox.|
The idea is far from new, and may even looks like old-school. However, the implementation they did is simple, really well done and really clever. Also, the wording they used in the tool is perfect (for example, using the word Follow instead of Subscribe).
The only problem is that this wonderful new tool is only available for WordPress.com users! As you may know, this blog is using WordPress, but it is a self-hosted instance. After doing some research, I couldn’t find any plugins or methods to install it on my blog. Also, the email service under this user interface is built into WordPress.com. As last resort, I checked their Jetpack plugin, to see if it got added the Follow Button to it, but apparently they didn’t (it is probably too recent).
So, I was in a dilemma: I wanted this feature for my blog, I didn’t want to migrate everything to WordPress.com, and I didn’t had the time to write a plugin that does exactly this. So what I did is to take a few hours to hack my own Follow Button using what is already existing out there. In fact, I have been quite surprised to see how easy it turned out to be.
It as been as easy as installing the really good Subscribe2 plugin and to create the UI, from the original Follow Button using some HTML, CSS and JQuery code. After some re-wiring, I ended-up with my own self-hosted Follow Button.
This is what I want to share with you here, in this Hors Série blog post. I am pretty sure that many self-hosted WordPress blogger will want it, so I took an additional hour to write and publish this blog post.
I did two additional “improvements” to the concept:
- I changed the icon to put some color in there. Not only to make it less dull, but also to bring a little bit mo attention to it.
- I also added a link to my RSS feed. To me, “Follow” is not just about emails, but it is also about other syndication mediums too. However, I kept the email as the first option to keep the spirit of the tool.
Finally, I didn’t want to hack any piece of code in WordPress nor in any other WordPress plugin. The only thing that we will modify is the theme, by adding some code to it. The current implementation could be improved by upgrading Subscriber2 for example, but I didn’t want people to have to do this to enable the Follow Button on their blog.
Step #1: Install Subscribe2
First thing first. The first thing you will have to do is to install the WordPress plugin that will enable your users to subscribe, and to manage their subscriptions, to your blog via emails. We are using the really good Subscribe2 WordPress Plugin that gives these features to your WordPress instance.
To install this plugin using WordPress’ automatic plugin installation system, follow these instructions. Read the plugin’s installation instruction if you want to do this the manual way:
- Log in to your WordPress blog and visit Plugins->Add New.
- Search for Subscribe2, click “Install Now” and then Activate the Plugin
- Click the “Settings” admin menu link, and select “Subscribe2”
- Configure the options to taste, including the email template and any categories which should be excluded from notification
- Click the “Tools” admin menu link, and select “Subscribers”
- Manually subscribe people as you see fit
- Create a WordPress Page to display the subscription form. When creating the page, you may click the “S2” button on the QuickBar to automatically insert the subscribe2 token. Or, if you prefer, you may manually insert the subscribe2 shortcode or token: [subscribe2] or the HTML invisible Ensure the token is on a line by itself and that it has a blank line above and below. This token will automatically be replaced by dynamic subscription information and will display all forms and messages as necessary
- In the WordPress “Settings” area for Subscribe2 select the page name in the “Appearance” section that of the WordPress page created in step 7
On this blog, I called the page created at step #7: Follow. Once you are done installing the plugin, you can test it by visiting your Follow page and by entering your own email (one that is not attached to any user of your account is preferable) and by checking in your inbox if you receive a subscription notification. If you haven’t, you may want to take a look at this FAQ to debug any possible issue with your outgoing email service.
Step #2: Customize your Follow Page
This next step is optional. Since that the form generated by the Subscribe2 plugin is really minimalist, you may want to customize it a little bit, to change its design and to add some explanation in the page, to help your readers to understand what is going on. Take a look at my own Follow page to see what I did to customize that page.
Step #3: Add the Follow Button code in you theme
The third step is really what will morph the Subscribe2 plugin into the Follow Button. What we are doing here, is just to add the code, in your theme, to display the Follow Button.
The first thing you have to do, is to locate where the footer of the pages is generated in the theme. Open the theme folder of your blog:
/../wordpress/wp-content/themes/mytheme/. Then you will have to open a few files to check where the
</body> ending HTML tag is generated. The file where that code is generated really depends on how the theme got designed. You can do a search, within all the PHP files in that folder for the string “
</body>“. This should give you the answer right away. Once you located that place, you are good to continue with the following instructions.
Important note: It is possible that your Theme doesn’t use jQuery by default. If it is the case, then you have to edit the
header.php (or whatever the name of the file where the header of your blog is generated) of your theme, and add the following line in the
<head>...</head> section of the page:
[cc lang=’html4strict’ line_numbers=’true’]
[cc lang=’html4strict’ line_numbers=’true’]
Or subscribe to the RSS feed by clicking on the counter:
The only thing you have to do is to copy/paste that code above the
</body> tag. Then, do the following three modifications to properly wire it in your blog:
- At line #41, replace
[[PATH-TO-THE-FAMFAM-ICON]]with the path of the
asterisk_orange.pngicon, on your blog
- At line #211, replace
[[PATH-TO-YOUR-FOLLOW-WORDPRESS-PAGE]]by the URL of your Follow page (the one you created when you installed Subscribe2)
- At line #228, replace
[[ADD-YOUR-RSS-FEED-LINK-HERE]]by the link to your RSS feed
You can get the free
asterisk_orange.png icon image from the FamFamFam website. The only thing you have to do, is to download that image, and to put it in the folder you defined for
[[PATH-TO-THE-FAMFAM-ICON]]. However, you can use whatever image that you prefer, that may better fit the design of your blog.
Step #4: Disable it For Mobile Devices
Some mobile devices may have issues displaying this floating window. Sometimes, the window may be floating in the middle of the device’s screen without folding-back in the bottom of the page. For this reason, you may want to disable (remove) this option if the user is using a mobile device to read your blog. You can easily disable it if the web server detects that a mobile devise is requesting the webpage by adding these two blocks of code.
First, copy and paste this first block of code above the code of the Follow button (before line #1):
[cc lang=’php’ line_numbers=’true’]
Then copy and paste this second block of code below the code of the follow button (after line #231):
[cc lang=’php’ line_numbers=’true’]
This code come from the Detect Mobile Browser project and is the best mobile device detection code I saw so far. What this code does, is not to include the Follow Button if the device that is requesting the webpage is a mobile device. Otherwise, the Follow Button is added to the HTML page.
Step #5: Test it!
If you are reading this step #5, it means that you finished to create your own, self-hosted, Follow Button!
But the last thing that remains to be done, is to test it. Once you saved your file with the code above, just refresh any page of your blog. You should see appearing the Follow button on the bottom-right corner of your blog. If you click on it, you should see the form that let your readers subscribing to the system. If you add one of your emails, and click the subscribe button, you should get redirected to the Follow page. Finally you should receive a confirmation email that ask you to confirm your subscription by clicking on a link.
If all these steps properly works, it means that you are done and ready to provide that new functionality to the readers of your blog!
Even if this blog post is few pages long, I hope you found it easy to install and setup. If you have any question regarding this hack, don’t hesitate to ask them down there, in the comments section of this post. I will be happy to answer all of them.
This blog post as been translated in Federico Bozo in Spanish. Other translations will be added to this section.