Image
 
 
 
 
 
 
 
 

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_head has fired is silently discarded.
  • Duplicate $block_id values are ignored.
  • CSS is minified in production (when WP_DEBUG is not true).

Changelog

VersionDescription
2.0.0Introduced.