link rel="alternate" type="text/plain"


The Logo for WordPress.

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 …

Continue reading →

Server-Side Rendering of Embedded Markdown Code Snippets in WordPress


The Logo for WordPress.

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…

Continue reading →

HOWTO: Sort BitWarden Passwords by Date


Screenshot of the BitWarden export page.

I highly recommend BitWarden as a password manager. It is free, open source, and has a great range of apps and APIs. The one thing it doesn't have is a way to sort your accounts by creation date. I now have over a thousand accounts that I've added - so I wanted to prune away some of the older ones. So, here's how to do it. Export your vault In the desktop version of BitWarden, go to File → E…

Continue reading →

eInk Display for Octopus's Agile Energy Tariff


An eInk screen with a line graph on it. The graph shows the current price of power. The eInk is mounted in a wooden frame.

I'm a little bit obsessed with building eInk displays. They're pretty cheap second hand. They're low energy, passive displays, with good-enough performance for occasional updates. Here's a new one which shows me what the current cost of my electricity is: Background After installing solar panels, a smart electricity meter, and a solar battery - the next obvious step was a smart energy…

Continue reading →

Publish Confirmation For WordPress Classic (2023)


Screenshot of a page asking for confirmation before publishing.

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…

Continue reading →

Find WordPress featured images with no alt text


The Logo for WordPress.

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…

Continue reading →

Find the URl causing your WordPress Error


The Logo for WordPress.

PHP has some pretty good error handling and logging, but I do sometimes find it confusing. For example, look at this warning message: [18-Oct-2023 12:34:56 UTC] PHP Warning: Something bad happened in /wp-content/something.php on line 123 OK, so we can go to something.php and scroll to line 123 and try to figure out what's gone wrong. But we don't know which page, post, or URl caused the error. …

Continue reading →

Displaying internal linkbacks on WordPress


Screenshot of my website. The headline says "What links here from around this site." Underneath are three links.

I have written a lot of blog posts. In some of those posts I link to other posts on my site. What's the easiest way of displaying those internal incoming links? Here's what it looks like: Code All we need to do is search WordPress for the URl of the current page. Loop through the results. Then display those links. $the_query = new WP_Query( array( 's' => get_the_permalink(), // …

Continue reading →

Making a better audio shortcode for WordPress


The Logo for WordPress.

If you use WordPress, you can get a fairly basic embedded audio player by using the audio shortcode: [​audio mp3="/path/to/file.mp3"] I didn't particularly like how it was styled so - because WordPress is so hackable - I changed it! Now my embedded audio looks like this: 🔊 Location Based QR Codes - Introducing http://xmts.mobi/🎤 edent 💾 Download this audio file. It gets a nice bord…

Continue reading →

Use WP CLI to find all blog posts without a featured image - two methods


The Logo for WordPress.

This uses the wp shell command. It gives you an interactive prompt into which you can do various WordPress "things". One small annoyance is that it doesn't like multi-line entry. It treats every hit of the enter key as "plz run the codez" - so, at the end of this blog post, I've put the commands in copy-n-paste format. Once you've installed WP CLIP, go to the command line and run wp shell.…

Continue reading →

Rewriting WordPress's JetPack Related Posts Shortcode


The new layout has 4 items, each boxed off, with a larger image and more distinct text.

I like the JetPack related post functionality. But I wanted to customise it far beyond what the default code allows for. So here's how I went from this: To this: Documentation The complete documentation for related posts is pretty easy to follow. This is an adaptation of "Use Jetpack_RelatedPosts_Raw to build your own list of Related Posts". Remove the automatic placement You can turn…

Continue reading →

Improving the WordPress Comments Form with Client-Side Validation


The Logo for WordPress.

If you use WordPress's HTML5 comments, there's an annoying little gotcha. There's a four year old bug which prevents client-side form validation. HTML allows <input> elements to have a required attribute. In theory, that means the form shouldn't submit until the input is filled in. Sadly, WordPress uses novalidate on the form - as the name suggests it stops any validation. But! WordPress is…

Continue reading →
OSZAR »