YAML Custom Fields allows you to define structured content schemas with an intuitive interface and ACF-like template functions. Perfect for theme developers who want flexible, schema-based content management without the complexity.
In your theme template:
<?php
$hero_title = ycf_get_field('hero_title');
$hero_image = ycf_get_image('hero_image', null, 'full');
$category = ycf_get_term('category');
$post_type = ycf_get_post_type('content_type');
$university = ycf_get_data_object('university');
$features = ycf_get_field('features');
?>
<div class="hero">
<?php if ($hero_image): ?>
<img src="<?php echo esc_url($hero_image['url']); ?>" alt="<?php echo esc_attr($hero_image['alt']); ?>">
<?php endif; ?>
<h1><?php echo esc_html($hero_title); ?></h1>
<?php if ($category): ?>
<span class="category"><?php echo esc_html($category->name); ?></span>
<?php endif; ?>
<?php if ($university): ?>
<p><?php echo esc_html($university['name']); ?></p>
<?php endif; ?>
</div>
Get a single field value:
$value = ycf_get_field('field_name');
$value = ycf_get_field('field_name', 123); // Specific post ID
$value = ycf_get_field('logo', 'partial:header.php'); // From partial
$value = ycf_get_field('title', null, $block); // From block context
Get image field with details:
$image = ycf_get_image('field_name', null, 'full');
$image = ycf_get_image('field_name', 123, 'thumbnail'); // Specific post ID
$image = ycf_get_image('icon', null, 'medium', $block); // From block context
// Returns: array('id', 'url', 'alt', 'title', 'caption', 'description', 'width', 'height')
Get file field with details:
$file = ycf_get_file('field_name', null);
$file = ycf_get_file('field_name', 123); // Specific post ID
$file = ycf_get_file('document', null, $block); // From block context
// Returns: array('id', 'url', 'path', 'filename', 'filesize', 'mime_type', 'title')
Get taxonomy field (term or terms):
$term = ycf_get_term('field_name', null);
$term = ycf_get_term('field_name', 123); // Specific post ID
$term = ycf_get_term('category', null, $block); // From block context
// Returns: WP_Term object or array of WP_Term objects (for multiple selection)
Get post type field:
$post_type = ycf_get_post_type('field_name', null);
$post_type = ycf_get_post_type('field_name', 123); // Specific post ID
$post_type = ycf_get_post_type('content_type', null, $block); // From block context
// Returns: WP_Post_Type object or null
Get data object field:
$university = ycf_get_data_object('field_name', null);
$university = ycf_get_data_object('field_name', 123); // Specific post ID
$university = ycf_get_data_object('university', null, $block); // From block context
// Returns: Array with data object entry fields or null
Get all entries of a data object type:
$all_universities = ycf_get_data_objects('universities');
foreach ($all_universities as $entry_id => $university) {
echo esc_html($university['name']);
}
// Returns: Array of all entries for the specified data object type
Get all fields:
$fields = ycf_get_fields();
$fields = ycf_get_fields(123); // Specific post ID
$fields = ycf_get_fields('partial:footer.php'); // From partial
Check if field exists:
if (ycf_has_field('hero_title')) {
echo ycf_get_field('hero_title');
}
Working with Block fields:
$blocks = ycf_get_field('features');
if (!empty($blocks)) {
foreach ($blocks as $block) {
// Access nested fields using context_data parameter
$title = ycf_get_field('title', null, $block);
$icon = ycf_get_image('icon', null, 'thumbnail', $block);
$category = ycf_get_term('category', null, $block);
echo '<h3>' . esc_html($title) . '</h3>';
if ($icon) {
echo '<img src="' . esc_url($icon['url']) . '">';
}
if ($category) {
echo '<span>' . esc_html($category->name) . '</span>';
}
}
}
fields:
- name: hero_title
label: Hero Title
type: string
required: true
options:
maxlength: 100
- name: hero_image
label: Hero Image
type: image
- name: category
label: Category
type: taxonomy
options:
taxonomy: category
- name: tags
label: Tags
type: taxonomy
multiple: true
options:
taxonomy: post_tag
- name: content_type
label: Content Type
type: post_type
- name: university
label: University
type: data_object
options:
object_type: universities
- name: features
label: Features
type: block
list: true
blockKey: type
blocks:
- name: feature
label: Feature Block
fields:
- name: title
label: Title
type: string
- name: icon
label: Icon
type: image
- name: description
label: Description
type: text
For custom partials, add the @ycf marker in the file header:
<?php
/**
* Custom Navigation Partial
* @ycf
*/
Then click “Refresh Template List” in the YAML Custom Fields admin page.
Template Global Fields allow you to define default values that are shared across all posts using the same template, while still allowing individual posts to override specific fields.
Setting up Template Global:
Using Template Global in Posts:
When editing a post that uses a template with Template Global fields, you’ll see a dual-field interface for each field:
Benefits:
Data Priority (when using template functions):
When a field uses template global, ycf_get_field() returns data in this priority order:
_yaml_cf_data_yaml_cf_use_template_global_fields (per-field array)yaml_cf_template_global_schemasyaml_cf_template_global_datayaml_cf_global_schemayaml_cf_global_datayaml_cf_partial_datayaml_cf_schemasyaml_cf_data_object_typesyaml_cf_data_object_entries_{type_slug}YAML Custom Fields does not collect, store, or transmit any user data outside of your WordPress installation. All data is stored locally in your WordPress database.
This plugin includes the following third-party libraries:
For documentation, examples, and support, visit:
* Plugin Documentation
* Report Issues