Microsoft buys LinkedIn: What it means for designers
On Monday, Microsoft and LinkedIn announced that Microsoft would buy LinkedIn in an all-cash deal for $196 a share, at $26.2 billion. In a news releas
With Instagram, Snapchat and other “young” social media platforms taking over the internet, Twitter still remains one of the most popular marketing channels.
It has around 326 million active users per month which means that your target audience is likely using it. This is why you should at least consider using it as a marketing channel for your business. Having Twitter as one of the main marketing channels is not only going to help build awareness of your brand but can also drive traffic to your website and make your articles go viral.
How can this be achieved? Well, it’s a pretty straightforward tactic that some of the top bloggers are using. The idea is that within your blog post you have short pieces of content that are catchy and people like them. Those pieces of content can then be easily tweeted. (For example, it could be a quote from someone who is an authority in your niche, or a statistic that you feel is likely to be shared by your visitors.)
So, let me show you how you can have “click to tweet” buttons added automatically to every quote in your article.
Before we get started, let me say that this is a medium-advanced technique. If you’re using WordPress you can use a ready-to-go plugin that will serve the same purpose.
Let’s assume that we want to turn from this article about conferences that says “According to webdesignerdepot.com …” into a tweetable block.
Given that we have the following html structure:
I only ever go to marketing conferences to meet new people and listen to their experiences. Those people never include the speakers, who are generally wrapped up in their own world and rarely give in the altruistic sense.
Here is how we would create a click to tweet button:
We need to collect all the and elements from our article when the document loads:
document.addEventListener("DOMContentLoaded", function() {
// Step 1. Get all quote elements inside the article
const articleBody = document.getElementById('article');
const quotes = [...articleBody.querySelectorAll('quote, blockquote')];Create additional variables to store the current page url, tweetable url and a ‘click to tweet’ button:
let tweetableUrl = ""; let clickToTweetBtn = null; const currentPageUrl = window.location.href;
We need to iterate over all the quote elements that we want to make tweetable and append a “click to tweet button” for each of them:
quotes.forEach(function (quote) {
// Create a tweetable url
tweetableUrl = makeTweetableUrl(
quote.innerText, currentPageUrl
);
// Create a 'click to tweet' button with appropriate attributes
clickToTweetBtn = document.createElement("a");
clickToTweetBtn.innerText = "Click to Tweet";
clickToTweetBtn.setAttribute("href", tweetableUrl);
clickToTweetBtn.onclick = onClickToTweet;
// Add button to every blockquote
quote.appendChild(clickToTweetBtn);
});
});Add 2 missing functions: makeTweetableUrl, that will create a tweetable URL, and onClickToTweet that will act as our event listener and open a window for the tweet (once the button is clicked):
function makeTweetableUrl(text, pageUrl) {
const tweetableText = "https://twitter.com/intent/tweet?url=" + pageUrl + "&text=" + encodeURIComponent(text);
return tweetableText;
}
function onClickToTweet(e) {
e.preventDefault();
window.open(
e.target.getAttribute("href"),
"twitterwindow",
"height=450, width=550, toolbar=0, location=0, menubar=0, directories=0,scrollbars=0"
);
}Here it is working on CodePen.
Now, let me show you a slightly different way to get the same result that you can implement if you’re using jQuery.
Here is the code:
$(document).ready(function() {
// Get all quote elements inside the article
const articleBody = $("#article");
const quotes = articleBody.find("quote, blockquote");
let tweetableUrl = "";
let clickToTweetBtn = null;
// Get a url of the current page
const currentPageUrl = window.location.href;
quotes.each(function (index, quote) {
const q = $(quote);
// Create a tweetable url
tweetableUrl = makeTweetableUrl(
q.text(), currentPageUrl
);
// Create a 'click to tweet' button with appropriate attributes
clickToTweetBtn = $("");
clickToTweetBtn.text("Click to Tweet");
clickToTweetBtn.attr("href", tweetableUrl);
clickToTweetBtn.on("click", onClickToTweet);
// Add button to every blockquote
q.append(clickToTweetBtn);
});
});
function makeTweetableUrl(text, pageUrl) {
const tweetableText = "https://twitter.com/intent/tweet?url=" + pageUrl + "&text=" + encodeURIComponent(text);
return tweetableText;
}
function onClickToTweet(e) {
e.preventDefault();
window.open(
e.target.getAttribute("href"),
"twitterwindow",
"height=450, width=550, toolbar=0, location=0, menubar=0, directories=0, scrollbars=0"
);
}As you can see, the code is the same, except that it takes advantage of jQuery’s functions to simplify the code we have to write. Here’s the jQuery version working on CodePen.
As you can see, creating a “click to tweet” button doesn’t require much time but it can be a great way to encourage your visitors to share your content on Twitter.
I hope this tutorial was helpful and you learned something new. Feel free to use this piece of code and implement it on your website.
Featured image via DepositPhotos.
On Monday, Microsoft and LinkedIn announced that Microsoft would buy LinkedIn in an all-cash deal for $196 a share, at $26.2 billion. In a news releas
A domain name is an essential element of every project, product, and company. It’s central to a brand and has a disproportionately large impact on use
Microsoft Paint is the poster child of a time forgotten. It’s been a standard app on Microsoft PCs for even longer than you think—38 years, to be prec
Augmented Reality is everywhere. Everyday, we read about it in the news. And even though Virtual Reality initially seemed to be a big deal—to have the
UX laws are an invaluable tool, providing guidelines for designers that ensure we don’t have to continually reinvent the wheel when crafting experienc
In the past, fantastic web design was a simple business. All you had to do was ensure that the design looked good in Internet Explorer or Netscape, an
We are a dynamic information platform dedicated to delivering timely, relevant, and reliable content across a broad spectrum of topics. From the latest in technology and business to lifestyle, health, and global affairs, we aim to keep our readers informed and inspired.
Our editorial team is committed to maintaining high standards of accuracy and clarity, ensuring that every article provides value and context in an ever-changing world. We believe in the importance of accessible knowledge and strive to make complex topics understandable for everyone.
Whether you're here to stay updated on current events, explore thought-provoking features, or simply learn something new, our goal is to offer a trustworthy source of information that meets the needs of a diverse and curious audience.