A testimonial: a quote, the name and role of the person who said it, and their photo if you have one. Your client types the words on the page. It is three plain files in your theme and a stylesheet.
Download example A zip of one block folder for your theme. Needs GCB 1.3.1 or later, and nothing else.
The whole block
Create blocks/testimonial/ in your theme. The folder name is the block's name, so this registers as gcb/testimonial.
block.json is WordPress's standard block metadata. There are no attributes in it and no render key: GCB makes the attributes from the fields and finds render.php by itself.
{ "apiVersion": 3, "name": "gcb/testimonial", "title": "Testimonial", "description": "A quote with the person's name and role, and a photo if you have one. Your client types the words on the page.", "category": "design", "icon": "format-quote", "supports": { "html": false }, "style": "file:./style.css"}block.fields.json lists the fields, in two groups that become panels in the sidebar. The quote and the name are required, and each has a length limit. The photo is an image field. It is drawn as a small round picture, so the settings that only suit a background (size, repeat, fixed and zoom) are turned off and the focal point is kept.
{ "controls": [ { "id": "p_words", "type": "group", "label": "Words" }, { "id": "p_photo", "type": "group", "label": "Photo" }, { "id": "c_quote", "type": "textarea", "label": "Quote", "attributeKey": "quote", "parentPanelId": "p_words", "default": "They listened, worked out what we needed and delivered it on time. We would work with them again.", "validation": { "required": true, "maxLength": 400 } }, { "id": "c_name", "type": "text", "label": "Name", "attributeKey": "name", "default": "Customer name", "parentPanelId": "p_words", "validation": { "required": true, "maxLength": 60 } }, { "id": "c_role", "type": "text", "label": "Role", "attributeKey": "role", "default": "Role, company", "parentPanelId": "p_words", "validation": { "maxLength": 80 } }, { "id": "c_photo", "type": "image", "label": "Photo", "attributeKey": "photo", "parentPanelId": "p_photo", "enableFocalPoint": true, "enableSizeOptions": false, "enableRepeatOptions": false, "enableFixedBackground": false, "enableZoom": false } ]}render.php is the template, for the editor and the page alike. It reads the values from $attributes. An element with data-gcb-field="<attributeKey>" and data-gcb-field-type="<type>" is edited where it sits on the page. A field with no marker appears in the block's sidebar.
The markup is a <figure> holding a <blockquote> and a <figcaption>, which is how HTML says who a quote is from. With no photo chosen, no <img> is printed. The photo's focal point becomes its object-position, so the crop to a circle keeps the face in frame.
<?php/** * Testimonial: a quote, who said it and their role, with a photo if there is one. * * The quote, the name and the role are marked data-gcb-field, so they are typed where they sit on the page. * The photo is optional: with none chosen, no <img> is printed and the name stands on its own. * * @var array $attributes The block's field values. */ // A field that stores an object (an image) can arrive as an object or an array.$as_array = static function ( $value ) { return is_object( $value ) ? json_decode( wp_json_encode( $value ), true ) : (array) $value;}; $photo = $as_array( $attributes['photo'] ?? array() );$focal = $as_array( $photo['focalPoint'] ?? array() ) + array( 'x' => 0.5, 'y' => 0.5 );$place = round( (float) $focal['x'] * 100 ) . '% ' . round( (float) $focal['y'] * 100 ) . '%';$role = (string) ( $attributes['role'] ?? '' );?><figure <?php echo get_block_wrapper_attributes( array( 'class' => 'testimonial-block' ) ); ?>> <blockquote class="testimonial-block__quote"> <p data-gcb-field="quote" data-gcb-field-type="textarea"><?php echo nl2br( esc_html( $attributes['quote'] ?? '' ) ); ?></p> </blockquote> <figcaption class="testimonial-block__by"> <?php if ( ! empty( $photo['url'] ) ) : ?> <img class="testimonial-block__photo" data-gcb-field="photo" data-gcb-field-type="image" src="<?php echo esc_url( $photo['url'] ); ?>" alt="<?php echo esc_attr( $photo['alt'] ?? '' ); ?>" width="56" height="56" loading="lazy" style="object-position:<?php echo esc_attr( $place ); ?>"> <?php endif; ?> <span class="testimonial-block__who"> <span class="testimonial-block__name" data-gcb-field="name" data-gcb-field-type="text"><?php echo esc_html( $attributes['name'] ?? '' ); ?></span> <?php if ( '' !== $role ) : ?> <span class="testimonial-block__role" data-gcb-field="role" data-gcb-field-type="text"><?php echo esc_html( $role ); ?></span> <?php endif; ?> </span> </figcaption></figure>style.css is a plain starting look, loaded by "style": "file:./style.css" in block.json. Replace it with your design.
.testimonial-block { margin: 0 auto; max-width: 720px; padding: clamp(28px, 5vw, 48px); border-radius: 14px; background: #f3efe8; color: #1d1b18; }.testimonial-block__quote { margin: 0; padding: 0; border: 0; }.testimonial-block__quote::before { content: "\201C"; display: block; height: 32px; font-size: 64px; line-height: 1; opacity: .3; }.testimonial-block__quote p { margin: 0; font-size: clamp(20px, 2.2vw, 26px); line-height: 1.45; }.testimonial-block__by { display: flex; align-items: center; gap: 14px; margin-top: 28px; }.testimonial-block__photo { flex: none; width: 56px; height: 56px; max-width: none; border-radius: 50%; object-fit: cover; background: #e3ddd2; }.testimonial-block__who { display: flex; flex-direction: column; gap: 2px; }.testimonial-block__name { font-weight: 700; }.testimonial-block__role { opacity: .7; }That is all of it. There is no edit.js, no npm and no build step: save the files, reload the editor, and the block is in the inserter.
What your client does
- Clicks the quote, the name or the role and types.
- Chooses a photo from the media library in the Photo panel, and sets its focal point.
- Leaves the photo empty when there isn't one. The name and role stand on their own.
They can't save the page with no quote or no name, or with a quote longer than 400 characters, and they can't change the layout.
Use it
- Unzip the download.
- Copy
testimonial/into your theme'sblocks/folder. - Reload the block editor. Testimonial is in the inserter.
That's all of it. You don't register the block: there's no register_block_type() call and nothing to add to functions.php. GCB registers every folder in your theme's blocks/ folder by itself.
More examples: all examples, or download them together as the GCB Kit. To build one from nothing, see how to build a block.