Snippet library
WordPress code snippets, ready to use.
707 free & Pro snippets and modules. Copy-paste-ready, or import in one click with SnipCraft.
Load More / Infinite Scroll Posts
Fetches additional posts from the WordPress REST API when a Load More button is clicked, with optional IntersectionObserver-based infinite scroll mode.
Highlight Search Terms on Page
Reads the search query from the URL (s, q, or search parameter) and wraps matching words in the page content with a highlighted mark element.
Read More / Read Less Toggle
Collapses long text blocks to a configurable height and adds a Read More / Read Less button that smoothly expands and collapses the content.
Copy Current Page URL Button
Copies the current page URL to the clipboard when any element with a data-copy-url attribute is clicked, with a brief visual confirmation.
Image Magnifier Zoom on Hover
Creates a circular magnifying-lens overlay that follows the cursor across any image tagged with a data-magnify attribute, showing a zoomed portion of the image.
Typewriter Text Effect
Cycles through a pipe-separated list of phrases on any element with a data-typewriter attribute, typing and deleting each phrase in turn.
Animated Number Counter on Scroll
Counts up numeric values inside elements with a data-counter attribute when they enter the viewport, using an eased animation for a polished statistics section.
Scrollspy Active Navigation Highlight
Watches in-page anchor links in the site navigation and adds an active class to the link whose corresponding section is currently in view.
Hide Header on Scroll Down
Slides the site header out of view when the user scrolls down and reveals it again on scroll up, keeping content visible on small screens.
Scheduled Cleanup of Unattached Media Files
Registers a weekly WP-Cron event that permanently deletes unattached media attachments older than 30 days to keep the media library tidy.
Allow Uploading Web Font Files
Adds WOFF, WOFF2, TTF, OTF, and EOT font formats to the WordPress upload allowlist so webfonts can be hosted in the media library.
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.