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

Reject Images That Exceed Maximum Dimensions

Blocks image uploads whose pixel dimensions exceed a configurable maximum, returning an error message before the file is saved.

#images#media#security
PHPPro

Strip EXIF Metadata From Uploaded Images

Removes EXIF metadata (GPS location, camera model, etc.) from uploaded JPEG images on upload to protect user privacy.

#exif#images#media
PHPPro

Allow Contributors to Upload Media

Grants the Contributor role the upload_files capability so contributors can add images and files without needing Editor access.

#media#permissions#roles
PHP

Link Featured Images to Their Post

Wraps featured images in archive and feed contexts with an anchor tag that links to the post permalink, so thumbnails are clickable.

#display#featured-image#link
PHPPro

Auto Set Featured Image From First Content Image

Automatically sets a post's featured image to the first inline image in its content when saved, if no featured image has been assigned.

#automation#content#featured-image
PHP

Set Default Featured Image Fallback

Outputs a placeholder featured image whenever a post has no thumbnail set, preventing broken or missing image areas in themes.

#display#fallback#featured-image
PHPPro

Auto-Convert Uploaded Images to WebP

Hooks the WordPress image-editor output format filter so that all generated sub-sizes (thumbnails) for JPEG and PNG uploads are produced as WebP instead, reducing file sizes (requires WordPress 5.8+ with GD or Imagick WebP support).

#images#media#performance
PHP

Increase Maximum Upload File Size

Raises the WordPress maximum upload size limit (used on media upload screens) to 256 MB.

#file-size#media#performance
PHP

Lowercase and Sanitize Upload Filenames

Converts uploaded filenames to lowercase and replaces spaces and special characters with hyphens for cleaner, URL-safe file paths.

#filenames#media#sanitize
PHPPro

Allow Additional Upload File Types

Extends the WordPress MIME allowlist to accept SVG, WebP, AVIF, and XML files, and fixes the upload security check so SVGs pass validation.

#files#media#mime-types
PHPPro

Rate-Limit a Custom REST Endpoint

Adds per-IP rate limiting to a custom REST endpoint using transients, returning HTTP 429 once a caller exceeds 30 requests per minute.

#rate-limiting#rest-api#security
PHPPro

Expose Custom Taxonomy Terms in REST API

Enables REST API and block editor visibility for an existing custom taxonomy by setting show_in_rest via the register_taxonomy_args filter.

#gutenberg#headless#rest-api
PHPPro

Require API Key for Custom REST Endpoint

Registers a protected GET endpoint at /wp-json/scseed/v1/protected-data that returns 401 unless the caller supplies a valid X-API-Key header.

#api-key#authentication#rest-api
PHPPro

Disable Specific REST API Routes

Removes the /wp/v2/users and single-user REST endpoints to prevent unauthenticated enumeration of user logins and IDs.

#access#rest-api#security
PHPPro

Add CORS Headers to REST API Responses

Adds Access-Control-Allow-Origin and related CORS headers to REST API responses so headless front ends on separate origins can make authenticated requests.

#cors#headless#rest-api
PHPPro

Register a Custom Read-Only REST Endpoint

Creates a public GET /wp-json/scseed/v1/site-info endpoint that returns the site name, URL, description, language, and timezone as JSON.

#endpoint#headless#json
PHPPro

Add Custom Post Meta Field to REST Response

Registers a custom _scseed_subtitle meta key on post objects in the REST API, exposing it for both reading and writing by authorised editors.

#custom-fields#meta#posts
PHP

Add Featured Image URL to Posts REST Response

Registers a featured_image_url field on the post REST object so headless themes can access the full-size image URL without an extra request.

#headless#images#posts
PHPPro

Restrict Plugin Activation to Super Admins on Multisite

Removes the activate_plugins capability from regular site admins on a multisite network so only super admins can activate or deactivate plugins.

#multisite#plugins#roles
PHPPro

Auto-Activate Plugins on New Multisite Sites

Automatically activates a predefined list of plugins on every newly created subsite in the network to enforce a consistent baseline setup.

#automation#multisite#network
PHPPro

Add Custom Column to Network Sites List

Inserts a "Last Post" column into the Network Admin Sites table showing the most recent published post date for each subsite.

#admin#multisite#network
PHPPro

Set Default Theme for New Multisite Sites

Automatically activates a specified theme on every newly provisioned subsite in a WordPress multisite network.

#automation#multisite#network
PHPPro

Allow Only Logged-In Users (Private Site Gate)

Redirects unauthenticated visitors to the login page for every front-end request, turning the site into a members-only experience.

#access#login#members
PHPPro

Custom Welcome Email to New Users

Sends a branded HTML welcome email to every new registrant with their login link, overriding the default WordPress notification.

#email#onboarding#registration