/** * Register hero block */ add_action('acf/init', 'hero'); function hero() { // check function exists if( function_exists('acf_register_block') ) { // register a hero block acf_register_block(array( 'name' => 'hero', 'title' => __('Hero'), 'description' => __('Image background with text & call to action.'), 'render_callback' => 'hero_render_callback', 'category' => 'formatting', 'icon' => 'format-image', 'mode' => 'preview', 'keywords' => array( 'hero', 'image' ), )); } } /** * This is the callback that displays the hero block * * @param array $block The block settings and attributes. * @param string $content The block content (emtpy string). * @param bool $is_preview True during AJAX preview. */ function hero_render_callback( $block, $content = '', $is_preview = false ) { // create id attribute for specific styling $id = 'hero-' . $block['id']; // create align class ("alignwide") from block setting ("wide") $align_class = $block['align'] ? 'align' . $block['align'] : ''; // ACF field variables $image = get_field('image'); $headline = get_field('headline'); $paragraph = get_field('paragraph'); $cta = get_field('cta'); ?>