Christian Heilmann

Quickie: A scriptless, imageless, no-third party code Twitter share button for WordPress

Tuesday, July 9th, 2013 at 9:43 pm

Pestered by my colleague Jason Weathersby (“you should have a share button on your blog, I don’t want to copy and paste the title and the URL”) I just added a “share on Twitter” button at the end of all my posts here on the blog. I looked at a few plugins and the official buttons and was not impressed as they all meant a lot of external JS and CSS and HTTP requests. That is not needed. So here is a Twitter Share button without any extra resources from the outside.

JS Bin

It is simple enough:

  • The structure of a “share on Twitter” URL is http://twitter.com/share?url={url to share}&text={text to share}&via={twitter name}
  • In WordPress you get the title of the current post in PHP with the_title() and the permalink of the post with the_permalink()
  • Put them together and you are done:

<p class="tweetthis">
  <a href="http://twitter.com/share
           ?url=<?php the_permalink();?>
           &text=<?php the_title();?>
           &via={your twitter name}" target="_blank">
    share on twitter
  </a>
</p>

Add some styling and we’re in the business. Want to add more sharing buttons without JS? Toby Osbourne has a good post on more URL structures of social sites.

Share on Mastodon (needs instance)

Share on BlueSky

Newsletter

Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:

160: Graphs and RAGs explained and VS Code extension hacks Graphs and RAG explained, how AI is reshaping UI and work, how to efficiently use Cursor, VS Code extensions security issues.
159: AI pipelines, 10x faster TypeScript, How to interview How to use LLMs to help you write code and how much electricity does that use? Is your API secure? 10x faster TypeScript thanks to Go!
158: 🕹️ Super Mario AI 🔑 API keys in LLMs 🤙🏾 Vibe Coding Why is AI playing Super Mario? How is hallucinating the least of our worries and what are rules for developing Safety Critical Code?
157: CUDA in Python, Gemini Code Assist and back-dooring LLMs We met with a CUDA expert from NVIDIA about the future of hardware, we look at how AI fails and how to play pong on 140 browser tabs.
156: Enterprise dead, all about Bluesky and React moves on! Learn about Bluesky as a platform, how to build a React App and how to speed up SQL. And play an impossible game in the browser.

My other work: