-
Enqueue Hooks: Four Hooks, Four Different Zones
– Four hooks mean four zones: front end, admin, editor only, editor together with the front end. – Mixing up the zones leaks styles where they should not be, or drops them where they are needed. – `$hook_suffix` in `admin_enqueue_scripts` stops files from loading on every admin screen.
-
The Illusion of a Schedule: Why WP-Cron Isn’t a Real Cron Job
– WP-Cron fires from visitors, not as a real background process. – A small site, a high-traffic site and an enterprise site each hit cron differently, so the fix differs too. – Control points: `cron_schedules`, `cron_request`, `wp_scheduled_delete`.
-
You’re a Tenant, Not the Owner: 6 Doors in Someone Else’s wp-admin
– wp-admin is a shared space between many plugins, and one plugin behaving badly hits every admin. – Six key hooks and “neighbourly etiquette”: prefixes, checking context, adding instead of replacing. – Professionalism means respecting the code sitting next to yours.
-
A Hook That Fires Twice — and How Not to Trigger an Infinite Loop When Saving a Post
– `save_post` fires several times for one save: autosave, revision, final save. – Calling `wp_update_post()` inside `save_post` causes recursion, so the action must be removed and re-added. – Each task deserves its own CRUD hook: `transition_post_status`, `wp_insert_post`, `save_post`, `before_delete_post`.
-
The Window of Opportunity: When Each WordPress Bootstrap Hook Is Open
– Bootstrap hooks are narrow time windows: code outside its window breaks silently or fatally. – Five startup stages: `muplugins_loaded` → `plugins_loaded` → `after_setup_theme` → `init` → `wp_loaded`. – Load-order bugs depend on the environment, which makes them hard to reproduce.
-
Head & Meta Hooks: The Silent Failures WordPress Won’t Warn You About
– `wp_title` does not work in block themes; `document_title_parts` replaces it. – Head/meta failures are silent: the code runs, but there is no warning. – Common traps: `echo` instead of `return` in `body_class`, and printing scripts directly instead of `wp_enqueue_script`.