Follow Me on Twitter CTA on Ghost and Wordpress
The other day I read a post on Hacker News about premature optimization in web application development. This was an excellent post in its own right, but one thing that jumped out at me was the call to action from the author to follow him on Twitter at the end of his post. I liked that it was subtle, simple, and effective (I followed him on Twitter). Naturally, I stole this idea for my own blogs. This method uses the Follow Button provided by Twitter. In this post, I will show you how to add your own “Follow Me on Twitter” Call to Action on your own Wordpress or Ghost blog.
Wordpress
I used the Bottom of Every Post Wordpress Plugin because I found that hacking the main wordpress loop caused my CTA to show up at the very bottom of a page rather than at the end of the post content. In addition, I made a small change to this plugin to make sure that it only appears on single posts rather than on the home page. Edit bottom-of-every-post/bottom_of_every_post.php from the Wordpress Plugins Editor and update the method to be:if( is_single() && file_exists( $fileName )){/* open the text file and read its contents */
$theFile = fopen( $fileName, “r”); $msg = fread( $theFile, filesize( $fileName )); fclose( $theFile );
/* detect the old message in code to try and eradicate my name and # showing up on strange websites that are run by lazy people */
if( $msg == “<p>Call for an estimate 724-498-1551<br><a href="mailto:[email protected]">[email protected]</a></p>” ){ $msg = “<p>Thank you for installing the Bottom of every post WordPress plugin. To find out how to change or remove this message, read <a href="https://wordpress.org/extend/plugins/bottom-of-every-post/installation/">the instructions</a>.</p>”; }
/* append the text file contents to the end of
the_content
*/ return $content . stripslashes( $msg ); } else{/* if
the_content
belongs to a page or our file is missing the result of this filter is no change tothe_content
*/return $content; }
is_single()
<p> If you made it this far, you should probably follow me on twitter. :) <a class="twitter-follow-button" href="https://twitter.com/levlaz"> Follow @levlaz</a> </p><script>window.twttr = (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return t; js = d.createElement(s); js.id = id; js.src = “https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
t._e = []; t.ready = function(f) { t._e.push(f); };
return t; }(document, “script”, “twitter-wjs”));</script>
I used ghosts code-injection tool to get this to work for every page. I added the following two scripts to the Blog Footer.
<script> article = document.getElementsByClassName('post-content'); child = document.createElement('p'); cta = '<p class="follow"> If you read this far, thank you! Follow me on Twitter to stay up to date on what the fuss is all about.<br />'; link = '<a class="twitter-follow-button" href="https://twitter.com/tralevnet"> Follow @tralevnet</a></p>' child.innerHTML = cta + link; article[0].appendChild(child); </script><script> window.twttr = (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return t; js = d.createElement(s); js.id = id; js.src = “https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
t._e = []; t.ready = function(f) { t._e.push(f); };
return t; }(document, “script”, “twitter-wjs”)); </script>
<style> .follow { line-height: 1.5; width: 50%; padding: 15px; border: dashed 1px lightgrey; font-size: smaller; color: #555; font-family: sans-serif; font-weight: bold; }.twitter-follow-button { margin-top: 10px; } </style>
Thank you for reading! Share your thoughts with me on mastodon or via email.
Check out some more stuff to read down below.
Most popular posts this month
- Daggerversary
- Setting up ANTLR4 on Windows
- SQLite DB Migrations with PRAGMA user_version
- My Custom Miniflux CSS Theme
- Installing Nextcloud on a FreeBSD VPS
Recent Favorite Blog Posts
This is a collection of the last 8 posts that I bookmarked.
- "Let's pick the right product for you". from jwz
- Automattic is doing open source dirty from David Heinemeier Hansson
- Setting Up Mastodon Author Tags from Robb Knight • Posts • Atom Feed
- Getting my next SWE role from Emmanuel Blogs
- Methods of Mandarin from Isaak.net
- 12 Months of Mandarin from Isaak.net
- Villages Without Cars from Straphanger
- Some Go web dev notes from Julia Evans
Articles from blogs I follow around the net
TCP Server in Zig - Part 4 - Multithreading
We finished Part 1 with a simple single-threaded server, which we could describe as: Create our socket Bind it to an address Put it in "server" mode (i.e. call listen on it) Accept a connection Application logic involving reading/writing to t…
via openmymind.net October 11, 2024Nebraska Woman Files Suit Against All Homosexuals
A Nebraska woman identifying herself as the "ambassador" for plaintiffs "God and His Son, Jesus Christ," is suing all homosexuals on Earth for breaking "religious and moral laws". In the suit, entered into the docket as Driskell v. …
via jwz October 10, 2024Pluralistic: Cars bricked by bankrupt EV company will stay bricked (10 Oct 2024)
Today's links Cars bricked by bankrupt EV company will stay bricked: "Software-based car" is a warning, not a slogan. Hey look at this: Delights to delectate. This day in history: 2009, 2014, 2019, 2023 Upcoming appearances: Where to find me. …
via Pluralistic: Daily links from Cory Doctorow October 10, 2024Generated by openring