Optimize Core Web Vitals (LCP, CLS and INP) in WordPress Core Web Vitals are three user-experience metrics that Google uses in its page experience signals:
systemd timers instead of crontab for WordPress maintenance Cron runs a command at a time and forgets about it: the output goes to a mail nobody reads, a failure goes unnoticed, and a job that runs longer than its interval starts a second time. A systemd timer starts a service unit instead, so each run…
Cache expensive operations with the WordPress Transients API The Transients API stores cached data with an expiration time. The same set_transient() and get_transient() calls use the wp_options table on a default install and memory (Redis, Memcached) when a persistent object cache is active, without any code changes. Good candidates are remote API responses, heavy WP_Query…
Use CSS container queries for component-level responsive design Media queries look at the viewport. But a component does not care how wide the window is, it cares how much space it has: a post card in a narrow sidebar and the same card in the wide main grid need different layouts at the same viewport…
Git submodules for a plugin shared across client sites An agency plugin used in eight client sites tends to end up as eight copies, each with its own small fixes. A Git submodule keeps the plugin in its own repository and puts it into each site repository as a pointer to one commit. A fix…
Offline support for a WordPress site with a service worker and Workbox A service worker is a script that the browser runs between the page and the network. It can answer requests from a cache, so pages the visitor has seen, or pages the site marks as important, open without a connection. For an event…
Full-text search in WordPress with MySQL MATCH AGAINST The built-in WordPress search runs LIKE '%word%' on the title, excerpt and content of every post. That reads the whole table for each search and sorts the results only roughly by relevance. On a site with tens of thousands of posts, a MySQL FULLTEXT index answers the…
Create WooCommerce variable products and variations with PHP Importing a catalogue from an old shop system often means hundreds of products with size and colour combinations. The WooCommerce CRUD classes create them in a few dozen lines: a WC_Product_Variable parent with its attributes, and one WC_Product_Variation per combination with price, SKU and stock.
Configure a Content Security Policy for WordPress A Content Security Policy (CSP) header tells the browser which sources a page may load scripts, styles, images, fonts and frames from, and whether inline scripts may run. With a strict policy, an XSS injection that slips through cannot run its script, because the browser refuses it. The…