Our national nightmare is over… or was it more of an annoyance? Whatever. For those interested, I have been increasingly publishing Tweets from my JackWellborn.com WordPress-based microblog. While I can’t reply to Tweets from my microblog, I can effectively quote them using links. The ideal behavior should work idiomatically across my microblog and RSS clients where the link should remain a simple link, and Twitter where the link should behave like a quote. Before this effort, I had a couple of flawed options. First, I could simply paste the unlinked URL. These plain URLs would successfully expand into quotes on Twitter and even be clickable on some RSS clients, but they were not clickable on my blog as well as some other RSS clients. Alternatively and ideally, I could make a hyperlink which worked on my blog and all RSS readers, and mostly worked on Twitter. Still these links led to a couple of problems.
The first problem I was trying to solve was disabling WordPress’s auto embedding feature. In case you don’t know, WordPress will automatically embed a whole Tweet whenever a link to Twitter is detected. While I believe this is truly a feature for many, if not most WordPress users, the auto-embedded content increased the length of my posts beyond microblog’s 280 character limit. This turned what I intended as microblog posts into regular blog posts. What shocked me was the lack of any sort of means to disable auto-embeds within WordPress’s admin UI, which led to that original oft quoted tweet1. After a few hours, I figured out you can disable Twitter embeds by manually removing providers using a built-in API. I added the following to my functions.php (you can find the full list of embed urls here):
wp_oembed_remove_provider('#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i');
wp_oembed_remove_provider('#https?://(www\.)?twitter\.com/\w{1,15}$#i');
wp_oembed_remove_provider('#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i');
wp_oembed_remove_provider('#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i');
wp_oembed_remove_provider('#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i');
wp_oembed_remove_provider('#https?://(www\.)?twitter\.com/i/moments/.*#i');
The second problem was the extra parentheses being added to Twitter posts. This was happening because the plugin I use to publish to Twitter didn’t quite know how to handle the Markdown I use to write my posts. I thought I could easily patch the publishing code to simply remove the parentheses using regular expression. I was right. In fact, I was so right that I am pretty sure my original attempt was either correct or very close to correct. So what happened? I am ashamed to admit, but at some point yesterday I started copying the modified plugin to the wrong directory. I have gotten fairly good at avoiding stupid mistakes, but stupid mistakes still get the best of me from time-to-time.
All in all, I am now in a position where my microblogging Twitter requirements are met. I can post a link to a Tweet and it stays a link in both my microblog and its RSS, and the link expands into a quote when published to Twitter. Perfect.
Sorry for all the noise.
-
The lack of configuration options in the UI really made me question the relationship between WordPress.org and the plugin marketplace. There’s no built-in way to disable auto embedding, but there’s a plugin that’d happily charge me $25 annually for that functionality. Think about that. ↩︎