Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
- $meta_boxes[] = [
- 'title' => 'Hero Content',
- 'id' => 'hero-content',
- 'description' => 'A custom hero content block',
- 'type' => 'block',
- 'icon' => 'awards',
- 'category' => 'layout',
- 'context' => 'side',
- 'render_callback' => 'my_hero_callback',
- 'supports' => [
- 'align' => ['wide', 'full'],
- ],
- // Block fields.
- 'fields' => [
- [
- 'type' => 'single_image',
- 'id' => 'image',
- 'name' => 'Image',
- ],
- [
- 'type' => 'text',
- 'id' => 'title',
- 'name' => 'Title',
- ],
- [
- 'type' => 'text',
- 'id' => 'subtitle',
- 'name' => 'Subtitle',
- ],
- [
- 'type' => 'textarea',
- 'id' => 'content',
- 'name' => 'Content',
- ],
- [
- 'type' => 'single_image',
- 'id' => 'signature',
- 'name' => 'Signature',
- ],
- [
- 'type' => 'text',
- 'id' => 'button_text',
- 'name' => 'Button Text',
- ],
- [
- 'type' => 'text',
- 'id' => 'button_url',
- 'name' => 'Button URL',
- ],
- [
- 'type' => 'color',
- 'id' => 'background_color',
- 'name' => 'Background Color',
- ],
- ],
- ];
- return $meta_boxes;
- } );
- function my_hero_callback( $attributes, $is_preview = false, $post_id = null ) {
- // Fields data.
- if ( empty( $attributes['data'] ) ) {
- return;
- }
- // Unique HTML ID if available.
- $id = 'hero-' . ( $attributes['id'] ?? '' );
- if ( ! empty( $attributes['anchor'] ) ) {
- $id = $attributes['anchor'];
- }
- // Custom CSS class name.
- $class = 'hero ' . ( $attributes['className'] ?? '' );
- if ( ! empty( $attributes['align'] ) ) {
- $class .= " align{$attributes['align']}";
- }
- ?>
- " class="" style="background-color: ">
- <img>">
- <?php $signature = mb_get_block_field( 'signature' ); ?>
- <img class="hero__signature" src="<?= $signature['full_url'] ?>">
- <?php if ( mb_get_block_field( 'button_url' ) ) : ?>
- <p><a class="hero__button" href="<?php mb_the_block_field( 'button_url' ) ?>"><?php mb_the_block_field( 'button_text' ) ?></a></p>
- <?php endif ?>
- </div>
- </div>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment