Infernal Backlinks
This morning I encountered a confounding problem wherein I clicked the link to a post that appears in today’s On This Day and got the content of a different post, notwithstanding the post’s content being correct on the backend. Despite having just woken up, I quickly traced the issue to the new way I’m displaying a post’s internal backlinks after the theme switch.
Since moving to the Shoreditch theme and not wanting to edit theme files or make a child theme, as I noted at the time my internal backlinks simply have been hooked to the_content()
, appended to the end of any post that has backlinks. This, somehow, is what is causing the issue. As such, I’ve temporarily disabled my function to display internal backlinks, although they continue to be generated as normal.
Initial attempts with ChatGPT have not solved the issue, and I’m giving some consideration to trying an alternative approach despite my worries about performance hits. Of course, at the moment I don’t even know if that approach can be implemented absent editing the theme files themselves.
Wordpress for decades has needed a solution for internal backlinks, and I remain as frustrated as ever that it exists neither natively nor anywhere in its expansive plugin ecosystem. This is a no-brainer feature that long since should have been implemented by Automattic itself.
Addenda
-
No need to try the alternative, as ChatGPT finally clocked the problem: we were using the variable
$content
twice, once referring to the current post and once referring to the content of the backlinked post, and so the content of the backlinked post replaced the content of the current post. I’ve altered the latter to use$backlink_content
and display of referring posts is working again. -
To be clearer: this wasn’t happening on all posts with backlinks. The issue was that when one of the backlinks was an untitled post, the code to generate what I call the “pseudo-title”—basically the first eight words followed by an ellipsis—is what was using
$content
again as the variable name. I hadn’t noticed the problem before today because this was the first time since the switch to hooking directly intothe_content()
that I’d clicked on a post with a backlink from an untitled post.