Created
March 17, 2025 06:01
-
-
Save neverything/7786c4659b737e0e134193d6d4c24f19 to your computer and use it in GitHub Desktop.
Add additional block styles from your child theme: https://silvanhagen.com/writing/additional-block-styles-child-theme
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 | |
namespace OllieChild; | |
function enqueue_custom_child_block_styles() { | |
// Scan our styles folder to locate block styles. | |
$files = glob( get_stylesheet_directory() . '/assets/blocks/*.css' ); | |
foreach ( $files as $file ) { | |
// Get the filename and core block name. | |
$filename = basename( $file, '.css' ); | |
$block_name = str_replace( 'core-', 'core/', $filename ); | |
wp_enqueue_block_style( | |
$block_name, | |
array( | |
'handle' => "ollie-child-block-{$filename}", | |
'src' => get_theme_file_uri( "assets/blocks/{$filename}.css" ), | |
'path' => get_theme_file_path( "assets/blocks/{$filename}.css" ), | |
) | |
); | |
} | |
} | |
add_action( 'init', __NAMESPACE__ . '\enqueue_custom_child_block_styles', 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment