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 →
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 →
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 →
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 →
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 →
You can now have this blog federated to your social media site by following @blog@shkspr.mobi If you're on Mastodon, it should look something like this: You should be able to follow it on Lemmy, kBin, PixelFed, and some cool social network I've never heard of. How This blog runs on WordPress. Thanks to the tireless work of Matthias Pfefferle, there's now an official WordPress ActivityPub plugin. It's pretty easy to set up - just install and click on settings. But there are a few niggles …
Continue reading →
People can subscribe to receive my blog via email. This is managed by the JetPack plugin. I want to be able to display something like "Join 1,234 subscribers and receive updates via email". So, how do I get the subscriber count from the API? As documented in the JetPack HTTP API, it is possible to interact with JetPack programmatically. A good starting point is /wp-json/ - that will show you all the API endpoints available on your blog. By filtering on "subscribers", we find: …
Continue reading →
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 →
There's a brilliant post by WordPress about how they've optimised some of the backend code to make it more efficient. So here's a suggestion for something else which can be optimised. If you want to schedule a blog post to be published later, you have to use this WordPress control: I find it mildly annoying. I don't get why part of it is a dropdown. And the number fields don't pop up my phone's number keypad. And I have to look at a different calendar if I want to schedule something for a…
Continue reading →
This is ridiculously niche. If this is of help to anyone other than to me... please shout! The IntenseDebate comment system is slowly dying. It hasn't received any updates from Automattic for years. Recently it stopped being able to let users submit new comments. So I've switched to Commentics which is a self-hosted PHP / MySQL comment system. It's lightweight, pretty good at respecting users' privacy, and very customisable. But it doesn't let you easily import comments. Here's how I fixed…
Continue reading →
I blog. A lot. Too much really. One of the things I like to do is see what I was rambling on about this time last year. And the year before that. And so on. So, here's my On This Day page and here's how I built it. WARNING Extremely quick and dirty code ahead! This allows you to add a shortcode like [ edent_on_this_day ] to a page and have it auto generate a list of posts you published on this day in previous years. You may need to exclude that page from your cache. Add these functions to…
Continue reading →
I recently read Darek Kay's excellent post about styling RSS feeds and wanted to do something similar. So, here's my simple guide to styling your WordPress blog's RSS / Atom theme. The end result is that if someone clicks on a link to your feed, they see something nicely formatted, like this: Prerequisites This involves editing your WordPress blog's theme. If you don't know what you're doing, you can mess up your blog. Make sure you take some backups before experimenting on your live…
Continue reading →