25% off ProSNIPC25OFF

Snippet library

JavaScript snippets for WordPress.

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

JavaScript

Auto-Update Cart on Quantity Change

Removes the 'Update cart' button and automatically submits the WooCommerce cart form whenever a quantity input value changes.

#cart#frontend#jquery
JavaScriptPro

Lazy YouTube Facade Click-to-Load

Replaces YouTube embeds with a lightweight thumbnail facade and play button; the actual iframe is only inserted after the user clicks, deferring the heavy YouTube scripts.

#embed#lazy-load#performance
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
JavaScriptPro

Auto-Collapse Long Comments

Collapses comment bodies taller than a threshold with an animated Read more / Read less toggle.

#accessibility#comments#frontend
JavaScriptPro

Comment Character Count and Limit

Displays a live character countdown on the comment textarea and blocks submission when the limit is exceeded.

#comments#forms#frontend