Editing the WordPress Twenty Twenty-Five Theme

A very angry Kris, clenching her teeth and fists

Edited 11/05/2025: Solved thanks to a very kind person on Mastodon! Head here if you want to see the answer to my frustrations below.

Or rather, trying to edit the theme and tearing my hair out for multiple hours… but I’m getting ahead of myself.

I’ve been using WordPress for ten years now. I use it to run two sites with thousands and thousands of pages and posts. I’ve customised child themes. I’ve written my own functionality with PHP and WordPress shortcodes. What I’m trying to say is: I’ve got some experience. It’s not my day job, but I’m not an idiot.

In 2018 WordPress introduced a new default editor called Gutenberg that was a much more visual, drag-and-drop interface. I hated it. Pretty much everybody hated it. I installed the Classic Editor plugin and never looked back.

Last year after I quit my job I decided to devote a bit more time to my sites, especially this blog. I started with a visual refresh, and I decided to bite the bullet and use the very latest default theme – Twenty Twenty-Five. It’s a “block theme,” and it took me a while to get my head around making changes in the Site Editor rather than in a child theme. But making changes was fast, and I got the site mostly looking the way I wanted it. I was reasonably happy.

This year I started a project to clean up my archives, which I call “tending my digital garden.” Every day I go to this page, which shows me all the posts for that calendar day going back 25 years. I scroll through them and look for stuff like broken links, missing tags and categories, malformed HTML. When I find one of them, I open it in the editor to fix it. This requires two clicks: 1) on the post title to open it in a new tab, and then 2) the “Edit Post” link in the admin toolbar. While this doesn’t seem like a lot, I’ve been doing it for hundreds of posts, every day since February. It adds up.

On my previous theme (Twenty Sixteen), each post had a little “Edit” link that would appear if you were logged in. You can see an example on my Roald Dahl site, which still uses that theme. So why doesn’t Twenty Twenty-Five?!

A screenshot from a post on RoaldDahlFans.com, showing an Edit link beneath a post

Today I decided I’d had enough, and it was time to figure out how to add it in. Very quickly I found this page: How to Add an Edit Post Link to WordPress Posts and Pages. It’s clear that there’s an existing WordPress core function that does exactly what I need: edit_post_link. All I needed to do was figure out how to get that into my template, and it should just work, right? Except not.

  1. I’ve worked with child themes before, so I started by creating a child theme for Twenty Twenty-Five. To my surprise, when I switched over to it, I lost all formatting and styles on the site. All of those changes I made in the Site Editor are saved in the database and only apply to the parent theme, not the child. WTF THAT SUCKS. There was no way I was going to recreate all that work, and I didn’t fancy the idea of trying to edit the database directly to reassign the saved configuration to a new theme. Let’s try the other option.
  2. I installed the WP Code plugin and found that it already has a built-in snippet that consists solely of edit_post_link. Perfect. You have two options of how to insert it: you can have it automatically appear at designated spots (like before or after a post excerpt), or you can use it as a shortcode.
    1. I started with the automatic locations. No matter which option I selected, the Edit link would either not appear or appear at the very top of the site (i.e. not attached to the post). It seems like however the plugin is determining the location just doesn’t work with the Twenty Twenty-Five theme.
    2. I switched over to the shortcode approach and added the shortcode to my template (using the Site Editor and the Shortcode block) below each post in the loop on the Archive page. When I viewed it, it looked like it worked! Every post had an Edit link at the bottom. However, I noticed quickly that all of them had the same postID, the very first one in the loop. It was clear that the context of the current post was not being picked up. That’s fine; I saw in the documentation that that you can supply a post ID to edit_post_link. Folks, I tried multiple different ways of getting the post ID in there and nothing worked. So this method was a bust.
  3. I went back to the child theme. I found a plugin called Create Block Theme that would clone your current theme AND all your Site Editor changes into a new child theme. I tried it out and it worked perfectly! I now had a child theme of Twenty Twenty-Five and could make changes directly to the templates in the code. Great. I connected to my host and started looking at the files… and for the life of me, I could not figure out where the hell to actually make my change. Block themes seem to use HTML files as well as PHP. I tried editing template PHP files; I tried adding things to functions.php. I just could not get it to work.

I asked Mastodon for help. I mostly got replies from people who misunderstood what I was trying to do or thought I was an idiot who couldn’t see the “Edit post” link in the toolbar. 🙄

Time for the nuclear option – I got Rodd and walked him through the problem, which meant painstakingly taking him through every bit of research I’d done and which options I’d tried and showing him how they didn’t work. He had some more ideas that we tried – including making a custom block type – but every approach either didn’t work or was way complicated for something that should be EASY. In fact, it should be BUILT-IN. Why the hell isn’t it included in this theme?!

In desperation I thought about doing it on the frontend. Maybe I could write some Javascript that would scrape the links on the post and… DUH, TAMPERMONKEY. I installed it and got it set up, and then pulled in Rodd for his superior DOM manipulation skills. Here’s our quick and dirty solution:

(function() {
   'use strict';

   document.querySelectorAll('.wp-block-post-date').forEach((el)=>{
      const a = document.createElement('a')
      a.href = '/wp-admin/post.php?action=edit&classic-editor&post=' + /archive[/](\d+)/.exec(el.querySelector('a').getAttribute('href'))[1]
      a.appendChild(document.createTextNode(' [Edit]'))
      el.appendChild(a)
   })
})();

Rodd thinks there are probably more elegant ways to do this, but it works. We look for posts with dates that contain a link, pull out the post ID with a regular expression, and add in a new appropriate “[Edit]” link. It works great, and it’s going to make my daily blog cleanup a lot faster!

A screenshot of web-goddess.org showing an [Edit] link next to the post date

If you know of how to edit the Twenty Twenty-Five child theme to include this, please let me know as I’d love to know how it’s actually meant to be done…

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Important Note

This site features content going all the way back to 2000. The posts you’ll read reflect my views and writing style at the time. While I have gone back to clean up a few of them, I think it’s important not to sanitise too much. This site is a record of who I am and how I’ve grown. Any blog post written years ago may not reflect who I am today, nor how I would write about the same topic today.