Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Created April 27, 2019 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/1d6dd743eadac57640e1f22609d004fe to your computer and use it in GitHub Desktop.
Save pbrocks/1d6dd743eadac57640e1f22609d004fe to your computer and use it in GitHub Desktop.
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