Last active
April 11, 2020 14:36
-
-
Save nathanrice/8ea2116df44465c733745575a1e174e4 to your computer and use it in GitHub Desktop.
A simple proof-of-concept for modularizing the CSS for each block, and linking it "just in time".
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 | |
// this snippet requires PHP 5.3+ | |
add_action( 'wp_enqueue_scripts', function() { | |
wp_register_style( 'atomic-blocks/ab-cta', '/path/to/atomic-blocks/css/ab-cta.css', array(), 1.0.0 ); | |
} ); | |
add_filter( 'render_block', function( $block_content, $block ) { | |
if ( 'atomic-blocks/ab-cta' === $block['blockName'] ) { | |
ob_start(); | |
wp_print_styles( $block['blockName'] ); | |
$block_content = ob_get_clean() . $block_content; | |
} | |
return $block_content; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment