I take great delight in seeing people reply to my blog posts. I use WebMentions to collect replies from social media and other sites. But which of my posts has the most comments? Here's a snipped to stick in your functions.php file. It allows you to add ?comment-order to any WordPress URl and have the posts with the most comments on top. // Add ordering by comments add_action( 'pre_get_posts', 'pre_get_posts_by_comments' ); function pre_get_posts_by_comments( $query ) { // Do nothing if …
Continue reading →
Here's a knotty problem. Lots of my posts use URl Fragments. Those are links which start with #. They allow me to write: <a href="#where-is-this-a-problem>Jump to heading</a> So when someone clicks on a link, they go straight to the relevant section. For example, they might want to skip straight to how to fix it. Isn't that clever? Where is this a problem? This works great when someone is on my website. They're on the page, and a fragment links straight to the correct section of that…
Continue reading →
Threads is Meta's attempt to disrupt the social media landscape. Whether you care for it or not, there are a lot of users there. And, sometimes, you have to go where the audience is. Here's how I build a really simple PHP tool to post to Threads using their official API. This allows you to send a single status update programatically, or regularly send new items from your RSS feed to an account. You can see the bot in action at https://www.threads.net/@openbenches_org Get the code The code…
Continue reading →
Some people like to receive this blog via email. I previously used JetPack to send out subscriber messages - but it became increasingly clear that Automattic isn't a good steward of such things. I couldn't find any services which would let me send a few thousand subscribers a few emails per week, at zero cost. So, redecentralise! I installed phpList which is an open source email campaign tool. My webhost - Krystal - had a one-click install option. But, phpList isn't quite one-click for…
Continue reading →
If your WordPress site has lots of plugins, it's sometimes difficult to keep track of what is manipulating your content. Ever wondered what priority all your various actions and filters have? This is a widget which will show you which actions are registered to your blog's hooks, and their priority order. It looks like this: Stick this code in your theme's functions.php or in its own plugin. function edent_priority_dashboard_widget_contents() { global $wp_filter; // Change this to …
Continue reading →
A scrap of code which I hope helps you. Problem You installed the WordPress JetPack plugin and wrote all your blog posts in Markdown. Now you want to remove JetPack or replace it with a better Markdown parser. You turn off JetPack's "Write posts or pages in plain-text Markdown syntax". You click edit on a post and see the HTML version of your page. Where did the Markdown version go? Background When you write using JetPack's Markdown plugin, the Markdown version is stored in…
Continue reading →
Dan Q very kindly shared his script to make WordPress do good HTML. But I couldn't get it working. Looking at the HTML it was spitting out, the meta generator said it was HTML Tidy version 5.6.0. That's quite old! I confirmed this by running: echo tidy_get_release(); Which spat out 2017/11/25. Aha! There are a few bugs in this version of HTML Tidy, some of which are fixed in later versions. Here's how to fix them. Auto Indent doesn't work. This is fixed by manually specifying "indent"…
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 →
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 →
I was noodling around in PHP the other day and discovered that this works: <?php $🍞 = "bread"; echo "Some delicious " . $🍞; I mean, there's no reason why it shouldn't work. An emoji is just a Unicode character (OK, not just a character - but we'll get on to that), so it should be fine to use anywhere. Emoji work perfectly well as function names: function 😺🐶() { echo "catdog!"; } 😺🐶(); Definitions: define( "❓", "huh?" ); echo ❓; And, well, pretty much everywhere: class 🦜 { publi…
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 →
A few weeks ago, I built an ActivityPub Server in a Single PHP File. It's a proof of concept showing how easy it is to turn a website into a full-featured Fediverse participant. After a bunch of feedback and testing, I've added a some features to make it slightly more useful. A single PHP file - 45KB of no-library goodness. Just add your details, upload, and done. No databases. Everything stored as JSON files on disk. Be followed. External users can discover and follow you. Send messages.…
Continue reading →