25% off ProSNIPC25OFF

Snippet library

PHP snippets for WordPress.

467 free & Pro snippets and modules. Copy-paste-ready, or import in one click with SnipCraft.

PHPPro

Dequeue Scripts and Styles by Page

Conditionally dequeues specified CSS and JS handles on pages where they are not needed, reducing per-page asset weight.

#assets#dequeue#optimization
PHPPro

Preload Hero/Featured Image

Outputs a rel='preload' hint for the current post's featured image on singular pages, prioritising its fetch to improve Largest Contentful Paint.

#images#lcp#optimization
PHPPro

Preload Critical Fonts

Outputs rel='preload' link hints in the document head for self-hosted web-font files so the browser fetches them at the highest priority.

#fonts#optimization#performance
PHP

Disable Core Lazy Loading

Removes the native loading='lazy' attribute that WordPress automatically adds to images and iframes, useful when a theme or plugin manages its own lazy loading.

#images#lazy-load#optimization
PHP

Disable Image Compression (Max Quality)

Forces WordPress to save uploaded images at 100% quality, disabling all lossy compression so originals are preserved exactly.

#compression#images#performance
PHP

Set JPEG and WebP Quality

Sets the JPEG and WebP compression quality WordPress uses when processing uploaded images to balance file size and visual fidelity.

#compression#images#optimization
PHPPro

Limit Which Image Sizes Generate

Restricts WordPress to generating only a specified allowlist of image sizes on upload, discarding all others to keep the uploads folder lean.

#images#optimization#performance
PHP

Disable Auto-Generated Image Sizes

Prevents WordPress from generating thumbnail, medium, medium_large, and large derivative files on upload, saving disk space.

#images#optimization#performance
PHP

Enable All Automatic Updates

Opts the site into automatic background updates for core (including major versions), plugins, themes, and translations.

#automation#maintenance#security
PHP

Disable All Automatic Updates

Disables all WordPress background auto-updates for core, plugins, themes, and translations to prevent unexpected version changes.

#automation#maintenance#stability
PHPPro

Test the Database Connection

Adds a Tools submenu page that runs diagnostic queries (SELECT 1, row counts, DB version) and reports the results.

#admin#database#diagnostics
PHPPro

Clear All Transients on Demand

Adds a Tools submenu page with a button that deletes every transient from the options table in a single query.

#admin#cache#database
PHPPro

Search and Replace Content Output

Substitutes one or more strings in post content and widget text on output, without touching the database.

#content#filters#maintenance
PHPPro

Enable Debug Logging via Snippet

Activates PHP error logging to wp-content/debug.log at runtime; ensures the file exists with safe permissions. Disable when debugging is complete.

#debugging#development#logging
PHPPro

Log 404 Errors to Database

Records each unique 404 URL, its referrer, and hit count to a custom database table so broken links can be identified and fixed.

#404#diagnostics#logging
PHP

Redirect All 404s to Homepage

Issues a 301 permanent redirect to the homepage for every 404 Not Found response, catching broken inbound links.

#404#maintenance#redirect
PHPPro

Increase Max Execution Time and Upload Size

Raises PHP time limits and upload size caps at runtime, giving long-running imports and large file uploads the headroom they need.

#maintenance#performance#php
PHP

Increase PHP Memory Limit

Raises the PHP memory limit to 512 MB for WordPress requests, useful when heavyweight plugins exhaust the default allocation.

#maintenance#memory#performance
PHP

Maintenance Mode for Non-Admins

Displays a 503 maintenance page to all non-administrator visitors while leaving the wp-admin dashboard accessible.

#503#development#maintenance
PHPPro

Notify Admin When New Admin Created

Emails the site administrator when any user account is granted the administrator role, to detect unexpected privilege escalation.

#audit#notifications#security
PHPPro

Alert Admin When Plugin Activated

Sends the site administrator an email with the plugin name, activating user, and timestamp whenever a plugin is activated.

#audit#notifications#plugins
PHPPro

Add Comment Form Honeypot

Inserts a hidden form field into the comment form that only bots fill in; any submission with a filled honeypot is silently rejected.

#comments#honeypot#security
PHPPro

Restrict Registration Email Domains

Blocks sign-ups from a list of known disposable and throwaway email providers to reduce spam accounts.

#email#registration#security
PHPPro

Block Bad Bots by User Agent

Denies requests from known scraper and harvester user agents with a 403 response.

#bots#security#spam