Skip to content
Ultivo Toolkit 1.0 is here! Get 10% off your first year with LAUNCH10 until September 30. See pricing
Documentation menu

Blocks & REST

Gutenberg blocks#

ultivo_register_block_type( array $settings ): array registers a Gutenberg block with a PHP render template, similar in spirit to ACF blocks:

add_action( 'ultivo/init', function () {
    ultivo_register_block_type( [
        'name'            => 'testimonial',
        'title'           => 'Testimonial',
        'description'     => 'A quote with an attribution.',
        'category'        => 'widgets',
        'icon'            => 'admin-comments',
        'render_template' => 'template-parts/blocks/testimonial.php',
    ] );
} );

Attach a field group to the block with the "Block" location rule, targeting the block by its full name (ultivo/testimonial). Editors then get those fields as controls in the block sidebar. Inside render_template, calling ultivo_get_field() (or ultivo_field()) automatically reads from the current block's data, no extra setup needed to know which block instance is rendering.

REST API#

Turn on Show in REST on a field group's settings to expose its values in REST API responses for the post types it targets. Values appear under a ultivo key on the post resource:

{
  "id": 42,
  "title": { "rendered": "About us" },
  "ultivo": {
    "hero_title": "Welcome to the site",
    "hero_image": { "url": "https://example.com/wp-content/uploads/hero.jpg" }
  }
}

Only fields belonging to a group with "Show in REST" enabled are included, and only for post types matched by that group's location rules.