25% off ProSNIPC25OFF

Snippet library

WordPress code snippets, ready to use.

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

JavaScriptPro

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.

#ajax#pagination#posts
JavaScriptPro

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.

#accessibility#highlight#search
JavaScript

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.

#accessibility#content#display
JavaScript

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.

#button#clipboard#sharing
JavaScriptPro

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.

#ecommerce#hover#images
JavaScriptPro

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.

#animation#frontend#text
JavaScriptPro

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.

#animation#counter#scroll
JavaScriptPro

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.

#anchor#menu#navigation
JavaScriptPro

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.

#animation#header#navigation
PHPPro

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.

#cleanup#cron#maintenance
PHPPro

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.

#admin#fonts#media
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