Skip to content

Instantly share code, notes, and snippets.

@psteinweber
Last active January 2, 2016 22:29
Show Gist options
  • Save psteinweber/8369833 to your computer and use it in GitHub Desktop.
Save psteinweber/8369833 to your computer and use it in GitHub Desktop.
#twitter #jquery This jquery snipped appends a "Click to tweet" button (font-awesome icon in this case) into every blockquote on the page. Created as a replacement for bulky "Click to tweet" wordpress plugins.
blockquote a:before {
content:"\f099";
font-family: FontAwesome;
margin-left: 10px;
}
var completeurl = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search;
completeurl = encodeURIComponent(completeurl);
var twshare = "https://twitter.com/share?url=" + completeurl;
$("blockquote").each(function () {
var $link = $("<a />"),
linkText = "",
url = twshare + "&text=" + $(this).text() + " @metamonks";
$link.attr("href", url);
$link.attr("title", "Tweet this");
$link.attr("target", "_blank");
$link.text(linkText);
$link.addClass('tweet-this');
$(this).append($link);
});
@jgentes
Copy link

jgentes commented Apr 22, 2015

Thanks, this was very helpful in creating a simple 'click to tweet' feature for Ghost.

@ryana
Copy link

ryana commented May 14, 2015

Awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment