Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
add_filter( 'acf/register_block_type_args', 'cameronjonesweb_automatically_enqueue_block_stylesheet' );
function cameronjonesweb_automatically_enqueue_block_stylesheet( $args ) {
if ( empty( $args['enqueue_style'] ) ) {
$file = get_template_directory_uri() . '/blocks/' . ltrim( $args['name'], 'acf/' ) . '/block.css';
if ( file_exists( str_replace( get_template_directory_uri(), get_template_directory(), $file ) ) ) {
$args['enqueue_style'] = $file;
}
}
return $args;
}
<?php
add_filter( 'acf/register_block_type_args', 'cameronjonesweb_common_block_render_callback' );
function cameronjonesweb_common_block_render_callback( $args ) {
if ( empty( $args['render_callback'] ) ) {
$args['render_callback'] = 'cameronjonesweb_block_render_callback';
}
return $args;
}
function cameronjonesweb_block_render_callback( $block, $content = '', $is_preview = false, $post_id = 0 ) {
$block_class = '';
if ( isset( $block['className'] ) && ! empty( $block['className'] ) ) {
$block_class .= $block['className'];
}
if ( isset( $block['align'] ) && ! empty( $block['align'] ) ) {
$block_class .= ' align'$block['align'];
}
echo '<div class=" ' esc_attr( $block_class ) . '">';
get_template_part( 'blocks/' . $block['name'] . '/block.php' );
echo '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment