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

Email Admin After Repeated Failed Logins

Tracks failed login attempts per IP using transients and emails the site admin when a configurable attempt threshold is crossed within a rolling window.

#brute-force#email#login
PHPPro

Add Google reCAPTCHA v3 to the Login Form

Integrates Google reCAPTCHA v3 into wp-login.php to silently score submissions and block likely-bot login attempts.

#authentication#bot-protection#login
PHP

Remove REST API Link Tag from Head

Removes the REST API discovery link from the HTML head and HTTP Link header to reduce information exposure to scanners.

#hardening#headers#privacy
PHP

Block Comments Containing Links

Automatically marks as spam any new comment that contains a URL, reducing link-spam without requiring CAPTCHA.

#comments#links#moderation
PHPPro

Allow Login by Email Address Only

Restricts the WordPress login form to email addresses only, rejecting plain username attempts with a friendly error message.

#authentication#email#hardening
PHPPro

Disable Login with Email Address (Username Only)

Rejects login attempts that use an email address, forcing users to enter their WordPress username instead.

#authentication#hardening#login
PHP

Disable PHP Error Display on the Front End

Suppresses PHP error, warning, and notice output on the public site so internal details are never leaked to visitors.

#errors#hardening#php
PHPPro

Block Visitors by IP Address

Denies access at the WordPress init stage to any visitor whose IP matches a configurable blocklist, returning a 403 Forbidden response.

#access-control#firewall#hardening
PHPPro

Limit WooCommerce Action Scheduler Retention

Reduces how long Action Scheduler retains completed and failed actions in the database, keeping the table small and cleanup queries fast.

#action-scheduler#cleanup#database
PHP

Set oEmbed Maximum Width

Caps the maximum width of embedded media such as YouTube and Vimeo via the embed_defaults filter to fit your content column.

#embeds#media#oembed
PHPPro

Set fetchpriority=high on the Hero Image

Adds fetchpriority="high" and removes lazy-loading from the post thumbnail on singular views to boost Largest Contentful Paint.

#core-web-vitals#fetchpriority#images
PHPPro

Lazy-Load Gravatars in Comments

Adds the native loading="lazy" attribute to all Gravatar img tags in the comments section to defer off-screen avatar network requests.

#comments#gravatars#images
PHPPro

Disable Dashicons for Logged-Out Visitors

Dequeues the Dashicons stylesheet on the public front end for visitors who are not logged in, saving an HTTP request and ~30 KB.

#css#dashicons#logged-out
PHPPro

Disable WooCommerce Cart Fragments AJAX

Dequeues the wc-cart-fragments script that fires an admin-ajax.php request on every page load, improving time to first byte on WooCommerce stores.

#ajax#cart#optimization
PHPPro

Self-Host Google Fonts Locally

Dequeues Google Fonts requests added by themes or plugins and enqueues a self-hosted fonts.css from the active theme instead.

#google-fonts#optimization#performance
PHPPro

Defer Non-Critical CSS Loading

Converts specified stylesheet handles to rel="preload" links with an onload swap, removing them from the render-blocking path.

#css#optimization#performance
PHPPro

Minify HTML Output

Strips unnecessary whitespace and blank lines from the HTML response to reduce page size, preserving pre/script/style/textarea content verbatim.

#html#minify#optimization
PHPPro

Disable WP-Cron and Use a Server Cron

Prevents WordPress from spawning its built-in cron on every page load and includes setup notes for a real server cron job.

#optimization#performance#scheduling
PHPPro

Add a Custom Field Column to a Post List

Adds a sortable meta-value column to the admin post list table for any post type and meta key.

#admin#column#cpt
PHP

Display Current Post's Taxonomy Terms via Shortcode

Shortcode [post_terms taxonomy="category"] lists the terms of any taxonomy assigned to the current post.

#cpt#display#shortcode
PHPPro

Make a Taxonomy Single-Select with Radio Buttons

Replaces the default taxonomy checkbox meta box with a radio-button list that enforces single-term selection.

#admin-ui#cpt#metabox
PHPPro

Register a Custom Post Status

Registers an 'Archived' post status for posts and pages, and adds it to the Classic Editor status dropdown.

#admin#cpt#custom-status
PHPPro

Add rel="sponsored" to Affiliate Links

Rewrites outbound links with the CSS class 'affiliate' or matching configured domains to carry rel="sponsored noopener".

#affiliate#content#links
PHP

Display Post Word Count Shortcode

Shortcode [word_count] displays the total word count of the current or any specified post.

#display#post#shortcode