Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Render an ACF field in a block for WordPress
<?php
/**
* Our combined block and shortcode renderer.
*
* We're not using sophisticated php, so if using the shortcode we'd need to specify all three values.
*
* @param array $attributes The attributes set on the block or shortcode.
*/
function acf_built_with_php_render( $attributes ) {
$return = '<h2 style="color:salmon;">' . ( print_r( $attributes['value_one'], true ) ?: 'value_one not defined' ) . '</h2>';
$return .= '<h4>' . print_r( get_field( 'the_title' ), true ) . '</h4>';
// $return .= '<h4>' . ( print_r( $attributes['value_two'], true ) ? print_r( get_field( 'the_title' ), true ) : print_r( $attributes['value_two'], true ) ), true ) . '</h4>';
$return .= '<p>' . print_r( $attributes['value_three'], true ) . '</p>';
$return .= '<h4>' . get_field( 'the_title' ) . '</h4>';
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment