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 register nav menu PHP – Custom Navigation

Register a custom menu location with register_nav_menus(), then render it in your template with wp_nav_menu(). Includes fallback handling and a full production header nav.

Use this whenever you need a custom header, footer, or sidebar navigation… ~5 min setup
View snippet
ACF
Beginner friendly

ACF Select Field — Use Choices as CSS Modifiers in PHP

Read an ACF Select field value and apply it as a BEM modifier class. Lets editors choose button style, card layout, or colour scheme from a fixed list.

Use this when editors need to choose a visual style — button… ~4 min setup
View snippet
ACF
Beginner friendly

ACF Relationship Field — Loop Related Posts in PHP

Loop through hand-picked related posts stored in an ACF Relationship field. Returns WP_Post objects — render title, permalink, and thumbnail without extra queries.

Use this when editors choose posts manually — "Related Articles", "See Also",… ~5 min setup
View snippet
ACF
Beginner-friendly

ACF Gallery Field with Lightbox

Loop through an ACF Gallery field, render thumbnails with srcset, and open full-size images in a vanilla JS lightbox — no plugins, no jQuery.

Use this when your page or custom post type needs a photo… ~10 min setup
View snippet
WordPress
Beginner-friendly

WordPress Custom Taxonomy Registration

Register a custom taxonomy in WordPress using register_taxonomy() — hierarchical (category-like) or flat (tag-like), with full i18n labels, REST API support, and permalink slugs.

Use this when your custom post type needs grouping or filtering —… ~5 min setup
View snippet
ACF
Beginner-friendly

ACF Repeater Field PHP — Loop Any List of Sub-Fields

A step-by-step PHP renderer for ACF Repeater fields — loop any list of sub-fields cleanly, with or without Flexible Content.

Use this when your editor needs to add, remove, or reorder list… ~4 min install
View snippet
WordPress
Beginner-friendly

Project Category Archive Navigation with 4 Column Grid

Build a project archive with an All link, project_cat term navigation, active archive classes, and a responsive 4 column project grid using native WordPress archive queries.

Use this when you want each project category to have its own… ~8 min setup
View snippet
ACF
Intermediate

ACF Post Grid — Dynamic Source with Grid or Carousel Layout

An ACF Flexible Content post-grid layout with two data sources — latest posts via WP_Query or hand-picked posts via a Relationship field — and two display modes: CSS…

Use this when you need a reusable "posts" section on any page… ~10 min setup
View snippet
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
Chat on WhatsApp