Created
April 27, 2019 16:41
-
-
Save pbrocks/1d6dd743eadac57640e1f22609d004fe to your computer and use it in GitHub Desktop.
Render an ACF field in a block for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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