Small, self-contained snippets for WordPress. PHP snippets are ready to copy into functions.php or a custom plugin. Shell scripts can be run directly for diagnostics.
Create a temporary administrator user via functions.php. REMOVE THIS CODE IMMEDIATELY after the user is created for security.
Features:
- One-time user creation on page load
- Checks if user already exists before creating
- Uses placeholder values that must be replaced (prevents accidental commits)
- Logs creation result to error log
- Safety check: aborts if placeholder values aren't replaced
Security Warning:
- NEVER commit this to version control
- Remove the code immediately after first login
- WP-CLI method (
admin-user-creation-wpcli.md) is preferred when available
Setup:
- Copy into your theme's
functions.phpor a mu-plugin - Replace
REPLACE_ME_USERNAME,REPLACE_ME@examp.le, andREPLACE_ME_PASSWORD - Load any page on your site once to trigger creation
- Log in with the new credentials
- IMMEDIATELY remove this code from functions.php
Recommended approach for creating WordPress administrator users safely from the command line.
Features:
- No code to add/remove from WordPress files
- Credentials aren't stored in files
- Full control via command line
- Secure random password generation examples
- Batch user creation from CSV files
- Emergency lockout recovery workflow
Quick Start:
wp user create temp_admin temp@example.com --role=administrator --user_pass="$(openssl rand -base64 16)"Auto-noindex posts past their expiry date via Yoast SEO, evaluated in the site's configured WordPress timezone.
Features:
- Adds a "Noindex After Date" meta box to the post edit sidebar
- Hooks into Yoast's
wpseo_robotsfilter — no manual Yoast config needed - Expiry triggers at midnight in the site's local timezone (reads from Settings → General → Timezone), not UTC
- Scoped to specific categories — set
$expiry_categoriesto limit which post categories are affected - Outputs
noindex, follow— removes from search results but keeps links crawlable
Use Cases:
- Race tips, event previews, or time-sensitive posts that should drop out of search results after the event
- Any content with a natural expiry date
Dependencies:
- Yoast SEO (free or premium)
- WordPress 5.3+ (
wp_timezone()added in 5.3)
Setup:
- Copy
post-expiry-noindex.phpinto your child theme'sfunctions.php(or a custom plugin) - Replace
$expiry_categories = [ 0 ]with your actual category IDs - Edit any post — the "Noindex After Date" field appears in the sidebar under Post settings
Create and manage WooCommerce product attributes (color, size, material, etc.) and their terms via WP-CLI. Includes Trellis VM and production SSH variants.
Features:
- Create global product attributes with correct
pa_slug convention - Add terms (values) individually or in a bash loop
- List attributes and terms in table format
- Delete attributes by ID
- Full end-to-end Trellis VM workflow example
Quick Start:
wp wc product_attribute create --name="Color" --slug="pa_color" --type="select" --user=admin --path=web/wpDependencies:
- WooCommerce installed and active
- WP-CLI with WooCommerce REST API support
Fix block theme templates that appear frozen — changes to PHP pattern files or .html template files are silently ignored because the Site Editor saved a DB override (wp_template post type) that takes precedence over the file on disk.
Features:
- Detect DB overrides by listing
wp_templateposts - Option A: delete the DB copy to restore file-system control
- Option B: surgically update specific block markup in the DB copy using
wp eval+str_replace - Trellis VM variants for all commands
- Prevention guidance (
WP_DEVELOPMENT_MODE=theme)
Quick Start:
# Find the frozen template post
wp post list --post_type=wp_template --fields=ID,post_name,post_status --path=web/wp --url=https://example.com/
# Delete it (restores file-system template)
wp post delete <ID> --force --path=web/wp --url=https://example.com/Converts images to WebP format optimized for WordPress featured images and Facebook Open Graph sharing. Uses the command cwebp -q 82 -resize 800 419 image.jpg -o image.webp to create 800×419 images that hit Facebook's 1.91:1 ratio requirement while fitting WordPress content columns (typically 645px wide).
Features:
- Single image and batch conversion examples
- Quality 82 for optimal balance of size and quality
- Metadata preservation option
- Nginx integration notes for automatic WebP serving
Dependencies:
webppackage (providescwebpcommand)
Setup:
- Install
cwebp(see Installation section in the snippet) - Run the conversion command on your images
- Use with Nginx
webp-avf.conf.j2fromnginx/image-optimization/for automatic serving