method_collect_css()
method_collect_css( string $css, string $block_id = '', int $priority = 10 )
Adds CSS to the consolidated block style collector.
Description
Global helper function that wraps Method_CSS_Collector::instance()->add(). Collects CSS from block render callbacks into a single <style id="block-instance-styles"> tag output in wp_head.
Parameters
$css (string) :
The CSS rules (without <style> tags).
$block_id (string) :
Optional unique identifier to prevent duplicate registrations. Typically the block’s generated #method-{id}.
$priority (int) :
Lower numbers output first. Default 10.
Return
(void)
Source
File: lib/class-method-css-collector.php
Usage
PHP
$css = method_get_block_responsive_styles( $attrs, $cssargs, array( 'base', 'mobile', 'tablet', 'wide' ), false );
method_collect_css( $css, '#' . $methodId, 10 );Notes
- CSS added after
wp_headhas fired is silently discarded. - Duplicate
$block_idvalues are ignored. - CSS is minified in production (when
WP_DEBUGis nottrue).
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |