
Hi folks,
The child theme of this blog was born in November 2015, on top of Twenty Fifteen. I built it from the HTML of a purchased one-page template, so it looked like my portfolio at that time. It worked, more or less, and then I did not touch it for years. When I moved the blog from WordPress 5.6 to 7.1 and from blog.hoja.in to hoja.in/blog this year, I finally opened the folder again. What I found was a small museum.
The most famous exhibit, the comment callback passed as a bare constant that is a fatal error on PHP 8, already got its own post about the WordPress upgrade. This post is about everything around it: how I found out what the theme really used, and how I rebuilt it in a way that the next upgrade will not hurt.
Problems I faced
A quick look at the old theme folder:
assets/css/with six stylesheets, among them a 15,000-linejs_composer.cssfrom a page builder, and an IE 8 stylesheet.assets/js/with its ownjquery.js1.11.2,jquery-migrate, a 270 KBplugins.js, the page builder’s front-end script and a private copy ofcomment-reply.min.js.assets/fonts/with Font Awesome and Bebas Neue in five formats each, including.eotfor very old Internet Explorer.- A
plugins/contact-form-7folder with a copy of the plugin’s CSS, although the plugin was not used. - Copies of many parent templates:
404.php,archive.php,category.php,content.php,search.php,single.php,page.php,comments.php.
And the funny ones, which I really have to confess:
category.phpstarted withecho "category";exit;. A debug line from 2015. Every category page of the blog showed the word “category” and nothing else. For years.index.phpcontained a comment form inside adisplay:nonediv, copied with the template’s demo HTML. Itsactionpointed to thewp-comments-post.phpof the template vendor’s demo site. Invisible, but sitting in the markup of every list page, and a form that posts to a third-party site has no business on a personal blog.header.phpprinted the stylesheets and jQuery as hard-coded<link>and<script>tags, whilefunctions.phpenqueued the parent stylesheet the official way and then dequeued it again with a later hook.
Solution
Step 1: Audit what is really referenced
Before deleting anything, I wanted a list of the assets that templates actually load. A grep over the PHP files gives that in one line:
cd wp-content/themes/myblog
grep -rhoE "assets/(css|js|fonts)/[^'"?]+" --include='*.php' . | sort | uniq -cOn the old theme this listed six stylesheets and six scripts. Three JavaScript files in the folder (jquery.min.js, jquery.form.min.js and the page builder’s front-end script) were not referenced anywhere: dead weight from day one. For the files that do appear, I asked the second question: does the page still need it? Icon fonts are easy to check; search the templates for the classes:
grep -rn "fa fa-" --include='*.php' . | wc -lThe old theme had 31 matches. Small decorative icons can be inline SVG or plain text; they do not justify an icon font in five formats. The same is true for jQuery, which was only there for the template’s lightbox and effect scripts that I did not want anymore.
Step 2: Enqueue, never hard-code
Hard-coded tags in header.php bypass everything WordPress knows about assets: dependencies, versions for cache busting, plugins that combine or defer files, and the guard that loads a script only once. So the rule for the new theme: header.php contains no asset tags at all, only wp_head().
If your child theme keeps the parent’s design, the documented pattern is to enqueue the parent stylesheet and make the child stylesheet depend on it:
add_action('wp_enqueue_scripts', function (): void {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style(
'child-style',
get_stylesheet_uri(),
['parent-style'],
wp_get_theme()->get('Version')
);
});My new theme does not use the parent’s look at all; it follows the portfolio design. So it enqueues one stylesheet and one deferred script of its own, removes the parent’s styles and scripts by their handles, and loads comment-reply from WordPress core only where threaded comments are possible. This is the real code from the theme:
function myblog_enqueue_assets(): void
{
$version = wp_get_theme()->get('Version');
$base = get_stylesheet_directory_uri() . '/assets';
wp_enqueue_style('myblog', $base . '/css/blog.css', [], $version);
wp_enqueue_script('myblog', $base . '/js/blog.js', [], $version, ['strategy' => 'defer', 'in_footer' => false]);
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'myblog_enqueue_assets', 20);
function myblog_dequeue_parent_assets(): void
{
foreach (['twentyfifteen-style', 'twentyfifteen-block-style', 'twentyfifteen-fonts', 'genericons', 'twentyfifteen-ie'] as $handle) {
wp_dequeue_style($handle);
}
foreach (['twentyfifteen-script', 'twentyfifteen-skip-link-focus-fix', 'twentyfifteen-keyboard-image-navigation'] as $handle) {
wp_dequeue_script($handle);
}
}
add_action('wp_enqueue_scripts', 'myblog_dequeue_parent_assets', 100);The array as fifth argument of wp_enqueue_script() with a loading strategy exists since WordPress 6.3. The fonts are self-hosted WOFF2 files under an open font licence, so the blog makes no request to a font CDN anymore, and the version from the theme header busts the browser cache on every theme release.
Step 3: Delete copied parent templates
This was the most important step and the least visible one. WordPress takes a template from the child theme first. A copy of the parent’s single.php from 2015 therefore hides every fix the parent made to that file in the years since. The parent theme is at version 4.3 now; my copies were from its first year.
For each copied template, I asked: does it differ from the parent in a way I still want? If not, delete it and let the template hierarchy fall back to the parent. In my case the answer was mostly “the whole design is new anyway”, so the new theme has a small set of its own templates and two of them are tiny on purpose:
<?php
// archive.php: categories, tags, dates and authors use the list layout of index.php
require __DIR__ . "/index.php";There is no category.php at all anymore. The template hierarchy goes from category.php to archive.php, and that one reuses the list. Fewer files, fewer places for an exit to hide.
Step 4: Check with debug mode on
Many PHP 8 problems in old themes are warnings, not fatals, so the page “works” and the log fills up. In the old comments.php, for example, the variables $aria_req and $required_text were defined in one branch and used in another. Locally I run with:
// wp-config.php (local only)
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);Then I open every template type once: front page, a single post with comments, a page, a category, a tag, a search result, a 404. After that wp-content/debug.log must be empty. If it is not, that is the work list. Comments matter here: the fatal callback bug only showed up on posts that had comments, so test at least one of those.
The result
The new theme has no jQuery, no icon font, no page builder leftovers and no copied parent templates. The comment callback is a proper function name in quotes, written with type declarations. Category pages show categories again, after many years. And I learned to search for exit; in every theme I inherit, including my own.
If you are also sitting on a 2015 child theme, give it one evening with the grep from step 1. You will be surprised. Feedbacks are the champion’s breakfast, so tell me what you found in yours!