
I logged into Twitter using a fresh account last week. No followers, no preferences set. The default experience was an unending slurry of racism and porn. I don't care to use Twitter any more. Whatever good that was there is now drowned in a cess-pit of violent filth. I still have a lot of Tweets embedded on this blog. Using WordPress, it was easy to paste in a link and have it converted to an embed. But I don't want to direct people to a dangerous site. So here's a somewhat automated way to …
Continue reading →
I am a pedant. I like it when validators say "nothing to report". No errors, no warnings, no information messages. My blog is plagued with messages on the HTML validator saying Info: Trailing slash on void elements has no effect and interacts badly with unquoted attribute values. By default, the WordPress function get_the_post_thumbnail() spits out HTML like: <img width="1024" height="593" src="example.jpg" alt="whatever" /> That final / is unnecessary. Having it there…
Continue reading →
HTML documents have the concept of an alternate representation of the document. For example, a page's header might say: <link rel="alternate" type="application/rss+xml" href="https://shkspr.mobi/blog/feed"> That tells you there's an alternative representation of the page, what sort of content it is, and where it is located. That's nice. But it's hard for a browser to tell the user what that page is. It might be able to guess from the type, but it isn't always certain. So the <link> element …
Continue reading →
Hot on the heels of yesterday's post, I've now made all of this blog available in text-only mode. Simply append .txt to the URl of any page and you'll get back the contents in plain UTF-8 text. No formatting, no images (although you can see the alt text), no nothing! Front page https://shkspr.mobi/blog/.txt This blog post https://shkspr.mobi/blog/2024/05/link-relalternate-typetext-plain/.txt A tag https://shkspr.mobi/blog/tag/solar.txt This was slightly tricky to get right! While there…
Continue reading →
This is a silly idea. But it works. I saw Dan Q wondering about plaintext WordPress themes - so I made one. This is what this blog looks like using it: The Code You only need two files. An index.php and a style.css. The CSS file can be empty, but it needs to exist - otherwise WordPress won't let you activate the theme. The index file displays the requested post, or front page, in plain text. It isn't the most sophisticated code I've ever written! header('Content-Type: text/plain; …
Continue reading →
I've launched a WordPress Plugin for an extremely niche use-case. WP GeSHi Highlight Redux works with WordPress's Classic Editor to convert Markdown to syntax highlighted code. That allows me to write: ```php $a = "Hello"; $b = 5 * 2; echo $a . str($b); ``` And have it displayed as: $a = "Hello"; $b = 5 * 2; echo $a . str($b); I've previously written about the WP GeSHi Highlight plugin. My plugin is a fork of that. It has the following changes: RSS & Atom feeds - disable code…
Continue reading →
Because I'm a grumpy old man, I don't use Gutenberg or Block themes on my WordPress. Instead, I write everything in Markdown. When I write code snippets in Markdown, they look like this: ```php $a = 1; echo $a; if ($a < 5) { // Do Something return thing( $a, true ); } ``` But I want to render that with code highlighting. I was using the Prismatic Plugin. It is excellent and very customisable. But it uses JavaScript to do the code highlighting. I want to respect my readers' time and …
Continue reading →
This is the 3,000th blog post I've published on this site! Bloody hell! I first started a blog on Blogger.com in 2004 - twenty years ago. Like all blogs, I managed half a dozen posts before I forgot about it. Cut to 2007 and I decided to launch shkspr.mobi as a weird site dedicated to rendering Shakespeare's plays in txt spk. Judging by Archive.org I was still using Blogger. By 2008 I was blogging most months. And then I never really stopped. In early 2009 I switched to WordPress which led…
Continue reading →
I use a self-built WordPress theme for this blog. I also use a variety of self-developed WordPress plugins for various enhancements. I used to publish these plugins, but I get terribly confused by the SVN shenanigans involved, and they weren't used by many people, so I stopped. Recently, I've been moving all my plugin code into my theme. This is sort-of-but-not-quite a MonoRepo. I've also tried to move away, as far as possible, from using other people's plugins. Most of the ones I had were …
Continue reading →
One of the things I love about having a database-backed blog like WordPress is that's it opens up a delightful range of possibilities for displaying content. I've read and reviewed around 300 books over the last few years. So I wrote a scrap of code which goes through all my book reviews, grabs their cover and rating, and displays them in a nice grid. You can visit it at shkspr.mobi/blog/library You know how when you're at a friend's home you rummage through their bookshelf? That's the same…
Continue reading →
Here's a quick scrap of code that works. There are lots of outdated tutorials out there for old versions of WordPress. This one is tested to be working in WordPress 6.3.2. This will pop up a confirmation dialogue when you try to publish, update, or schedule a post or page. The Code Add this to your theme's functions.php file: add_action( "admin_footer", "confirm_publish" ); function confirm_publish() { echo <<< EOT <script> var publishButton =…
Continue reading →
WordPress allows you to set a featured image - called a "thumbnail" in the API. This gives a single image which can be used on a listing page, or shown when a post is shared on social media. The WordPress Media Library lets you set the alt text of an image. But, crucially, this alt text can be different when the image is used as a featured image. Here's how to find all your featured images which don't have alt text. One Liner Paste this into wp shell to get a list. foreach (get_posts(…
Continue reading →