Snippet library
PHP snippets for WordPress.
467 free & Pro snippets and modules. Copy-paste-ready, or import in one click with SnipCraft.
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.
Strip EXIF Metadata From Uploaded Images
Removes EXIF metadata (GPS location, camera model, etc.) from uploaded JPEG images on upload to protect user privacy.
Allow Contributors to Upload Media
Grants the Contributor role the upload_files capability so contributors can add images and files without needing Editor access.
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.
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.
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.
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).
Increase Maximum Upload File Size
Raises the WordPress maximum upload size limit (used on media upload screens) to 256 MB.
Lowercase and Sanitize Upload Filenames
Converts uploaded filenames to lowercase and replaces spaces and special characters with hyphens for cleaner, URL-safe file paths.
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.
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.
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.
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.
Disable Specific REST API Routes
Removes the /wp/v2/users and single-user REST endpoints to prevent unauthenticated enumeration of user logins and IDs.
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.
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.
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.
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.
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.
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.
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.
Set Default Theme for New Multisite Sites
Automatically activates a specified theme on every newly provisioned subsite in a WordPress multisite network.
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.
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.