A row of logos with a heading above it, for "trusted by", "stocked by" or "as seen in". Your client adds each logo from the media library and can give it a link. It is three plain files in your theme and a stylesheet, and it ships with no pictures.
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/logo-strip/ in your theme. The folder name is the block's name, so this registers as gcb/logo-strip.
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/logo-strip", "title": "Logo strip", "description": "A row of logos your client adds from the media library, with a heading if you want one.", "category": "design", "icon": "images-alt2", "supports": { "html": false, "align": [ "wide", "full" ] }, "style": "file:./style.css"}block.fields.json lists two fields: a heading, and the logos. The logos are a repeater of up to 12 rows. Each row has an image field and a text field for an address. "contained": "logos" on the image says the picture must always show whole: it is never cropped, and it gets a Scale setting, from 80 to 125 per cent, for a logo that reads small or large beside the others.
{ "controls": [ { "id": "c_heading", "type": "text", "label": "Heading", "attributeKey": "heading", "default": "Trusted by", "validation": { "maxLength": 60 } }, { "id": "c_logos", "type": "repeater", "label": "Logos", "attributeKey": "logos", "addButtonLabel": "Add logo", "max": 12, "fields": [ { "id": "logo", "type": "image", "label": "Logo", "attributeKey": "logo", "contained": "logos" }, { "id": "link", "type": "text", "label": "Link (optional)", "attributeKey": "link", "placeholder": "https://" } ] } ]}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.
Here the heading has a marker and the logos are kept in the sidebar. Each logo's Scale becomes a CSS variable the stylesheet multiplies its size by. A logo with an address is wrapped in a link, and one with no alt text takes the picture's title as its name. With no logos, the page prints nothing, and the editor's preview says to add some.
<?php/** * Logo strip: a heading and a row of logos. * * The heading is typed on the page. The logos are rows of a repeater field, kept in the sidebar: each row is a * picture from the media library and, if you give it one, an address the logo links to. A logo is always shown * whole, and its Scale (80 to 125 per cent) evens out one that reads small or large beside the others. * * @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;}; $heading = (string) ( $attributes['heading'] ?? '' );$logos = array(); foreach ( (array) ( $attributes['logos'] ?? array() ) as $row ) { $row = $as_array( $row ); $logo = $as_array( $row['logo'] ?? array() ); if ( ! empty( $logo['url'] ) ) { $logos[] = array( 'url' => $logo['url'], // A linked logo needs a name, so fall back to the picture's title. 'alt' => (string) ( ( $logo['alt'] ?? '' ) ?: ( $logo['title'] ?? '' ) ), 'width' => (int) ( $logo['width'] ?? 0 ), 'height' => (int) ( $logo['height'] ?? 0 ), 'scale' => max( 80, min( 125, (float) ( $logo['scale'] ?? 100 ) ) ) / 100, // esc_url() empties an address it won't allow, and then the logo isn't linked. 'link' => esc_url( trim( (string) ( $row['link'] ?? '' ) ) ), ); }} // The editor draws its preview through the REST API. There, an empty strip says what to do next.$in_editor = ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || is_admin(); if ( ! $logos && ! $in_editor ) { return;}?><section <?php echo get_block_wrapper_attributes( array( 'class' => 'logo-strip' ) ); ?>> <?php if ( '' !== $heading ) : ?> <p class="logo-strip__heading" data-gcb-field="heading" data-gcb-field-type="text"><?php echo esc_html( $heading ); ?></p> <?php endif; ?> <?php if ( $logos ) : ?> <ul class="logo-strip__list" role="list"> <?php foreach ( $logos as $logo ) : ?> <li class="logo-strip__item" style="--logo-scale:<?php echo esc_attr( $logo['scale'] ); ?>"> <?php if ( '' !== $logo['link'] ) : ?> <a href="<?php echo esc_url( $logo['link'] ); ?>"> <?php endif; ?> <img src="<?php echo esc_url( $logo['url'] ); ?>" alt="<?php echo esc_attr( $logo['alt'] ); ?>"<?php echo $logo['width'] && $logo['height'] ? ' width="' . esc_attr( $logo['width'] ) . '" height="' . esc_attr( $logo['height'] ) . '"' : ''; ?> loading="lazy"> <?php if ( '' !== $logo['link'] ) : ?> </a> <?php endif; ?> </li> <?php endforeach; ?> </ul> <?php else : ?> <p class="logo-strip__empty"><?php esc_html_e( 'Add logos in the sidebar.', 'default' ); ?></p> <?php endif; ?></section>style.css is a plain starting look, loaded by "style": "file:./style.css" in block.json. Replace it with your design.
.logo-strip { text-align: center; }.logo-strip__heading { margin: 0 0 24px; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; opacity: .7; }.logo-strip__list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 28px clamp(28px, 5vw, 64px); }.logo-strip__item { margin: 0; }.logo-strip__item a { display: block; border-radius: 4px; }.logo-strip__item a:focus-visible { outline: 2px solid currentColor; outline-offset: 6px; }.logo-strip__item img { display: block; width: auto; height: auto; max-width: calc(160px * var(--logo-scale, 1)); max-height: calc(44px * var(--logo-scale, 1)); object-fit: contain; }.logo-strip__empty { margin: 0; padding: 24px; border: 1px dashed color-mix(in srgb, currentColor 30%, transparent); border-radius: 10px; 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 heading and types.
- Presses Add logo in the sidebar and chooses a picture from the media library.
- Sets a logo's Scale when it looks too small or too large in the row.
- Types an address to make a logo a link.
- Drags the rows to reorder the logos, and removes one.
They can't add a thirteenth logo, and a logo is never cropped or stretched.
Use it
- Unzip the download.
- Copy
logo-strip/into your theme'sblocks/folder. - Reload the block editor. Logo strip 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.