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.

PHP

Enqueue a Custom Editor-Only Stylesheet

Loads a theme stylesheet only inside the block editor so you can fine-tune typography and spacing without affecting the front end.

#admin#css#editor
PHP

Add Theme Support for Editor Styles and Wide Alignment

Declares editor-styles, align-wide, and responsive-embeds theme support so the block editor applies the active theme stylesheet and enables wide/full-width alignment controls.

#css#editor#gutenberg
PHP

Register Custom Block Pattern Category

Registers a "Site Layouts" block pattern category so custom patterns registered with that slug appear in their own section of the pattern inserter.

#blocks#editor#gutenberg
PHP

Unregister Unwanted Core Block Styles

Removes the built-in Fill, Outline (button), Rounded (image), and decorative separator block styles to keep the editor style panel tidy.

#blocks#customization#editor
PHP

Set Site Name and No-Reply From Address for wp_mail

Overrides the default WordPress email sender name with the site name and the from address with a noreply@ address derived from the site domain.

#email#mail#notifications
PHP

Register Custom WP-Cron Intervals

Adds "Every 15 Minutes" and "Twice Daily" schedule intervals to the WP-Cron system for use with wp_schedule_event().

#automation#cron#performance
PHP

Allow WebP and AVIF Image Uploads

Adds WebP and AVIF to WordPress allowed upload MIME types so modern image formats can be uploaded through the media library.

#images#media#mime-types
PHP

Force Attachment Pages to Download File

Intercepts attachment page requests and serves the attached file as a forced browser download instead of displaying the page.

#attachments#download#files
PHP

Disable WordPress Big Image Size Threshold

Prevents WordPress from down-scaling large uploaded images by disabling the 2560px big-image threshold.

#images#media#performance
PHP

Auto-Set Image Alt Text from Filename

Automatically populates the alt text meta for newly uploaded images using the sanitized attachment filename.

#accessibility#images#media
PHP

Register Custom Image Size (Editor-Selectable)

Registers a 600x400 hard-cropped "Card" image size and adds it to the block editor image size dropdown.

#block-editor#editor#images
PHPPro

Add Custom Field to WooCommerce Checkout

Adds an optional "Order Notes Extra" text field to the checkout form, saves it as order meta, and displays it in the admin order view.

#checkout#custom-field#frontend
PHPPro

Hide WooCommerce Prices and Add-to-Cart for Guest Users

Replaces product prices and the Add-to-Cart button with a "Login to see prices" message for non-logged-in visitors.

#access-control#frontend#guests
PHPPro

WooCommerce Minimum Order Amount Enforcement

Prevents checkout and displays a cart notice when the order total falls below a configurable minimum amount.

#checkout#frontend#orders
PHPPro

Redirect to Cart After WooCommerce Add-to-Cart

Skips the "Added to cart" notice and immediately redirects the customer to the cart page after a product is added.

#cart#conversion#frontend
PHPPro

WooCommerce Percentage Sale Badge

Replaces the default "Sale!" product badge with the actual percentage discount (e.g. "-25%").

#badge#conversion#frontend
PHPPro

WooCommerce Free Shipping Progress Notice

Displays a dynamic notice in the cart showing how much more the customer needs to spend to qualify for free shipping.

#cart#conversion#frontend
PHP

Add Trust Badge Message Below Add-to-Cart

Inserts a short security / money-back-guarantee trust message directly below the Add-to-Cart button.

#conversion#frontend#shop
PHP

Change WooCommerce Related Products Count

Controls how many related products are shown on the single product page (default WooCommerce shows 4).

#frontend#product#related
PHP

Custom WooCommerce Out-of-Stock Text

Replaces the default "Out of stock" availability text with a custom message on product pages.

#frontend#product#shop
PHP

Custom WooCommerce Thank-You Page Message

Displays a personalised thank-you message with the customer's first name on the order confirmation page.

#checkout#frontend#orders
PHP

Remove All WooCommerce Product Data Tabs

Hides the Description, Additional Information, and Reviews tabs from the single product page.

#frontend#product#shop
PHP

Change WooCommerce Add-to-Cart Button Text

Replaces the default "Add to cart" button label with "Buy Now" on both single product and archive pages.

#add-to-cart#frontend#shop
PHPPro

Responsive Embed Wrapper via the_content

Wraps iframes and embeds (YouTube, Vimeo, etc.) found in post content in a responsive aspect-ratio container.

#content#embeds#frontend