Code Snippets

A small, field-tested developer library .

Practical, copy-ready snippets from real WordPress, WooCommerce and frontend projects — written to drop straight into a theme, child theme or component.

WordPress
Beginner-friendly

WordPress Archive Query — pre_get_posts Control PHP

A focused pre_get_posts helper for changing archive page sizes per post type without touching admin screens, secondary queries, or unrelated blog archives.

Useful when your theme has multiple post type archives that need different… ~4 min setup
View snippet
WordPress
Beginner-friendly

WordPress Custom Post Type — CPT Registration PHP Boilerplate

A clean, well-commented boilerplate for registering custom post types in WordPress — with proper labels, REST API support, archive configuration, and filter hooks for child theme overrides.

Use this when you're building a WordPress theme that needs custom content… ~5 min setup
View snippet
Performance
Snippet

Defer WordPress Scripts — Non-Critical JS Safely with PHP

Defer non-critical WordPress scripts (contact forms, sliders, analytics) without breaking jQuery dependencies — using wp_script_add_data, conditional loading, and WordPress filter hooks. No plugin needed.

Use this when your PageSpeed or Lighthouse audit flags render-blocking scripts —… ~8 min setup
View snippet
Shopify
Beginner-friendly

Shopify Product Badge — Tags and Metafields Liquid

Display a product badge (New, Sale, Sold Out, Made in ___) based on product tags, metafields, or inventory status — one Liquid snippet, consistent across collection pages and…

Use this when product cards need visual signals — "New Arrival," "On… ~3 min setup
View snippet
Shopify
Intermediate

Shopify AJAX Cart Drawer — Quantity Updates Without Reload

Add quantity increment/decrement buttons to the Shopify cart drawer with AJAX updates — no page reload, optimistic UI, and proper error handling using the Shopify AJAX API.

Use this when your cart drawer shows item quantities as plain text… ~10 min setup
View snippet
Shopify
Intermediate

Shopify Product Metafield — Clean Liquid Render Pattern

A reusable Liquid snippet that safely renders Shopify product metafields with type detection, fallback handling, and null safety — one include, every metafield on the site.

Use this when your theme renders product metafields — size charts, care… ~4 min setup
View snippet
WooCommerce
Beginner-friendly

WooCommerce Sale Badge Percentage — Discount Display PHP

Display a "Sale" badge with the actual percentage discount on WooCommerce product cards — using product price comparison, simple math, and WooCommerce action hooks. No template overrides needed.

Use this when you want product cards to show exactly how much… ~3 min setup
View snippet
WooCommerce
Intermediate

WooCommerce Checkout Notice — Conditional Cart Total Alert

Display a notice on the WooCommerce checkout page when the cart total meets a threshold — free shipping eligibility, bulk discount qualification, or minimum order requirements — using…

Use this when you want to nudge customers toward a higher cart… ~5 min setup
View snippet
WooCommerce
Intermediate

WooCommerce Custom Checkout Field — Add and Validate with PHP

Add a custom field to the WooCommerce checkout form with server-side validation, order meta storage, and admin display — using WordPress filter hooks, not template overrides.

Use this when WooCommerce's default checkout fields don't capture everything you need… ~10 min setup
View snippet
Chat on WhatsApp