Last active
October 7, 2020 23:21
-
-
Save cameronjonesweb/d0e865b680aeebad826e23a652d54ee0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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; | |
} |
This file contains hidden or 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 | |
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