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. If the error only occurs on /page/test?input=6 and not /page/test?output=7 that would be handy…

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(), // This post 'post_type' => 'post', // Only posts, not pages "posts_per_page" =>…

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 border, a title, displays any attached image, and uses the native HTML5 audio element. Here's the code …

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. You'll be greeted with an interactive prompt wp> Method One - Quick Search This command constructs a…

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 off the original "related posts" by adding this to your theme's functions.php: function…

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 very hackable. Here's how to make a comment form which does client-side validation and as a bonus…

Continue reading →

Better Bluetooth Sound Quality on Microsoft Teams in Windows 11


Screenshot of a Windows setting screen.

Here's the problem: the current Bluetooth spec doesn't allow high-quality audio to be sent to a headset when it is also sending audio from the microphone. Instead, it switches to the Hands Free Profile (HFP) which only streams low quality mono sound. It makes Teams calls sound like garbage. The usual solution in Google Meet, Zoom, and MS Teams is to manually tell the app to use Bluetooth for speakers but a separate mic for input. In my experience, that never works with Teams. It forces HFP…

Continue reading →

How to use the new <search> element with WordPress


The Logo for WordPress.

There's a new HTML element in town! You can now use <search> to semantically mark up a search box. It's great for letting screen-readers and other assistive tech know what a form does. It's only supported in WebKit for now - other browsers will get it eventually. The WordPress default search widget hasn't yet updated, but I'm going to show you how you can start using it today! In your theme, create a new file called searchform.php - WordPress will automatically load it for the search widget. …

Continue reading →

Using Selenium & Chrome to automatically download Blob files


Logo of the Python programming language.

The Selenium WebDriver is a brilliant way to programmatically interact with websites. You can write little Python scripts which can click around inside browser windows and do "stuff". I use it to download a file generated by a Javascript Blob and automatically save it to disk. Here's how. Set up the WebDriver After you've installed Selenium and the Chrome WebDriver, this is the standard boilerplate to use it in Python: from selenium import webdriver from selenium.webdriver.chrome.options…

Continue reading →

Automatically deleting WordPress comments using a theme


The Logo for WordPress.

Let's say you want to automatically delete specific sorts of comments from your WordPress blog. For example, immediately trashing any comment that has a specific phrase "Elephant Juice" in it. You can do this by going to Settings -> Discussion → Disallowed Comment Keys. Or you can add something to your theme's functions.php file. Here's the code snippet: add_action( 'comment_post', 'check_comment_content', 10, 2 ); function check_comment_content( $comment_id, $comment_approved ) { $…

Continue reading →

Mosh supports .ssh/config


Unix is user-friendly — it's just choosy about who its friends are.

I've recently started using Mosh. It's a clever bit of software that keeps your SSH sessions running, even if your client goes offline or changes IP address. But I find the syntax used to launch it a bit verbose and easy to forget. A typical command is something like: mosh --ssh="ssh -p 1234" myname@example.com Within the FAQ is a fleeting mention of how to configure Mosh. It says: Q: How do I use a different SSH port (not 22)? As of Mosh 1.2, you can pass arguments to ssh like so: …

Continue reading →

Add Swipe Gestures to Firefox on Wayland in Pop_OS


Unix is user-friendly — it's just choosy about who its friends are.

tl;dr - edit the file ~/.bash.rc add the line export MOZ_ENABLE_WAYLAND=1 then reboot. Once done, type into the Firefox address bar about:support and check that "Window Protocol" is set to "wayland". You can configure how swipes work by visiting about:config and filtering for "swipe": I'll say this for Linux - why have two different ways to accomplish something when you can have twenty? It seems there are dozens of different places where you can set environment variables - I've seen…

Continue reading →