ACF snippets

ACF code snippets.

Practical ACF snippets from real client builds, written to drop into production themes, child themes, and custom components.

ACF
Intermediate

ACF Button Link Component — Reusable PHP Renderer

A reusable wrapper for ACF Link fields — null-safe rendering, variant system for primary/secondary/ghost/outline styles, optional inline SVG icons positioned before or after the label, and full attribute…

Use this when your theme has buttons powered by ACF Link fields… ~5 min setup
View snippet
ACF
Snippet

ACF Flexible Content Renderer — Reusable PHP Without Switch/Case

Stop writing giant if/else chains for ACF Flexible Content. This system maps each layout to its own template file — add new layouts without touching the renderer.

Use this when your Flexible Content field has more than 3 layouts,… ~15 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
ACF
Snippet

ACF Image Field Renderer — Alt Text Fallback PHP

A production-ready image renderer for ACF Image fields — responsive tags with a four-level alt text fallback chain, srcset generation from registered image sizes, lazy loading, decoding async,…

Use this when your theme renders ACF Image fields in flexible content… ~3 min setup
View snippet
ACF
Intermediate

ACF Options Page Helper — Global Theme Settings PHP

A thin wrapper around ACF options page fields — type-safe helpers with default fallbacks, proper escaping, and one function call per field. No scattering get_field(..., 'option') across your…

Use this when your theme has an ACF Options page for global… ~4 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
ACF
Snippet

ACF Post Source WordPress — Latest or Manual Selection PHP

Build a reusable ACF Flexible Content section where editors can dynamically choose their post source — latest posts or hand-picked selections — without writing a single line of…

Use this on client sites where editors need control over which content… ~10 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 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
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
Chat on WhatsApp