brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp scaffold child-theme makes a WordPress child theme in one command

WordPress
~/tips/tip-wordpress-scaffold-child-theme

wp scaffold child-theme my-child --parent_theme=twentytwentyone --theme_name="My child" --activate

Creates a WordPress child theme so your theme changes survive updates of the parent theme.

Edit the CSS or the functions.php of a theme you downloaded and the next theme update wipes your changes. A child theme is the fix that everyone knows about and nobody likes setting up by hand. WP-CLI writes it for you.

Give it a slug for the new theme and the parent it builds on:

wp scaffold child-theme my-child --parent_theme=twentytwentyone --theme_name="My child" --activate

That creates wp-content/themes/my-child with two files. style.css has the header WordPress needs, with Template: twentytwentyone as the link to the parent. functions.php loads the parent stylesheet first and then the child’s, so your CSS wins. --activate switches the site to the child right away; leave it off if you want to look at the files first. --author and --theme_uri fill the remaining header lines.

The parent theme must be installed, and the slug you pass to --parent_theme is the name of its folder, which isn’t always the display name. wp theme list shows the right one.

Two caveats. Customizer settings and menu locations are stored per theme, in an option named after the theme, so switching to a child can make the site look a bit different until you set those again. Do it on staging first, or at a quiet moment. And the generated functions.php loads both stylesheets with a fixed version 0.1.0, which ends up in the URL. Browsers and caching plugins can hold on to the old CSS after you change it, so bump that number when you do. With a block theme much of the design lives in the Site Editor anyway, so I’d only reach for a child theme there when I need real code changes.

Further reading: wp scaffold child-theme (WP-CLI commands), Child themes (Theme Handbook)

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link