Directory / plugin

YAML Custom Fields

v2.0.0 · by starbist

Custom fields for pages, posts and every part of the site. You set the fields once. Writers fill them in.

About this plugin

YAML Custom Fields adds boxes to fill in on pages, like “Headline”, “Team photo” or “Event date”. Writers fill them in. The website shows them in the right place.

You list the fields of each page template in a short text, called a schema. Each field takes a few lines.

What it does

  • Gives each page template its own fields.
  • Adds fields to the header, the footer and other site parts.
  • Adds shared fields: one value for every page with the same template.
  • Keeps site details, like a phone number, for the whole site.
  • Lets writers build pages from sections they add, remove and reorder.
  • Keeps collections, like team members, for any page to pick from.
  • Exports and imports fields and content, for backups or moving to another site.
  • Finds missing images and files, and content left behind by removed fields.
  • Shows fields in block themes with a shortcode.
  • Makes fields available over the REST API.

Field types

  • One line of text
  • Several lines of text
  • Text with formatting (bold, links, lists)
  • Code, like an embed or a form
  • Yes or no (tick box)
  • Number
  • Date, with or without time
  • Dropdown
  • Category or tag
  • Kind of content (posts, pages and more)
  • Item from a collection
  • Image, or a gallery
  • File, or several files
  • Group of fields
  • Sections
  • Info box: a note for writers
  • Section heading: a title with a gap above it

How it works

  1. Go to YAML CF and switch on Custom fields for a template.
  2. Click Create schema and list the fields:

    fields:

    • name: headline
      label: Headline
      type: string
    • name: photo
      label: Photo
      type: image
  3. Open a page that uses the template. The fields are in a “Custom fields” box. In the block editor it’s below the content. In the classic editor it’s below the title.

  4. Show each field in the theme with one line:

The Documentation page in the plugin explains every step in plain words.

Developer Documentation

The full guide is on the plugin’s Documentation page. Here’s the short version.

Functions

ycf_get_field( 'name' )                        // One field
ycf_get_field( 'name', 42 )                    // A field of another post
ycf_get_field( 'name', 'partial:header.php' )  // A site part
ycf_get_field( 'title', null, $section )       // A field inside a section
ycf_get_fields()                               // All fields
ycf_has_field( 'name' )                        // Does it have a value?
ycf_get_image( 'name', null, 'large' )         // Image: id, url, alt, title, caption, width, height
ycf_get_file( 'name' )                         // File: id, url, path, filename, filesize, mime_type, title
ycf_get_term( 'name' )                         // Category or tag (WP_Term)
ycf_get_post_type( 'name' )                    // Content type (WP_Post_Type)
ycf_get_data_object( 'name' )                  // An item from a collection
ycf_get_data_objects( 'short-name' )           // Every item in a collection
ycf_get_global_field( 'name' )                 // One site detail
ycf_get_global_fields()                        // All site details

Each function also has a long name starting with yaml_cf_.

Always escape what you print: esc_html() for text, esc_url() for links, wp_kses_post() for formatted text. Code fields print as they are.

Shortcode

[ycf field="headline"]
[ycf field="hero" size="large"]
[ycf field="phone" source="site"]
[ycf field="subtitle" default="Coming soon"]

Where data is stored

  • Page fields: post meta _yaml_cf_data
  • Schemas: option yaml_cf_schemas
  • Site parts: option yaml_cf_partial_data
  • Shared fields: options yaml_cf_template_global_schemas and yaml_cf_template_global_data
  • Site details: options yaml_cf_global_schema and yaml_cf_global_data
  • Collections: option yaml_cf_data_object_types. Each item has its own option, plus a small index per collection. Read them with ycf_get_data_objects().

Privacy Policy

YAML Custom Fields doesn’t collect or send any data. Everything stays in your WordPress database.

Third-Party Libraries

  • Symfony YAML (6.4), MIT license (works with GPL)
    • Homepage: https://symfony.com/components/Yaml
    • License: https://github.com/symfony/yaml/blob/6.4/LICENSE

Credits

Support

Plugin tags