admin管理员组文章数量:1122832
If you use wp_head()
in the header of your theme Wordpress generated a style tag for the Gutenberg block editor.
Who knows how you can get the generated css style tag with the styles without using wp_head()
?
If you use wp_head()
in the header of your theme Wordpress generated a style tag for the Gutenberg block editor.
Who knows how you can get the generated css style tag with the styles without using wp_head()
?
1 Answer
Reset to default 1We can look at the source of the wp_head()
function:
function wp_head() {
/**
* Prints scripts or data in the head tag on the front end.
*
* @since 1.5.0
*/
do_action( 'wp_head' );
}
And see that it really only calls the wp_head
hook. We can then look through the WordPress core code for hooked functions that output the styles. From what I could discern in wp-includes/default-filters.php
, the main function could be wp_print_styles
:
add_action( 'wp_head', 'wp_print_styles', 8 );
This is further supported when we look at the function description for wp_print_styles
:
Displays styles that are in the $handles queue.
However, this will print out all enqueued CSS, not those only for blocks. You'd also want to ensure that all styles are enqueued too by ensuring wp_enqueue_scripts
function has run (this is also hooked into wp_head
).
If you need to only have CSS enqueued for blocks, you may need to look at hooking into hooks to determine if a CSS asset is enqueued from a block. For example, you could use the render_block
hook to get a list of view_style_handle
s and style_handle
s. Plus, you'd want to look at styles rendered by various block supports.
本文标签: phpGet generated block styles programmatically
版权声明:本文标题:php - Get generated block styles programmatically 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308119a1933549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论