admin管理员组文章数量:1022544
I have registered a custom block with ACFs acf_register_block
. I have set a render_callback
to load a php template but would like to access any extra CSS classes which the user may have set in the admin.
Does WordPress provide a global like $block
(similar to $post
) or would I need to raise a question on the ACF support forums?
I have registered a custom block with ACFs acf_register_block
. I have set a render_callback
to load a php template but would like to access any extra CSS classes which the user may have set in the admin.
Does WordPress provide a global like $block
(similar to $post
) or would I need to raise a question on the ACF support forums?
1 Answer
Reset to default 8Note that I don't have ACF PRO 5.8 which comes with the Block features, but I hope this answer helps.
If you look at the example here, you can retrieve the additional/custom CSS classes using props.attributes.className
; i.e. the classes are saved as an attribute named className
.
So with that in mind and based on acf_register_block()
(which as of writing, it redirects to acf_register_block_type()
), your render_callback
function would receive a $block
array (the block settings and attributes) as the first argument, and therefore you should be able to retrieve the additional CSS class(es) via $block['className']
as shown here — see the example under "Registering a block with callback".
I have registered a custom block with ACFs acf_register_block
. I have set a render_callback
to load a php template but would like to access any extra CSS classes which the user may have set in the admin.
Does WordPress provide a global like $block
(similar to $post
) or would I need to raise a question on the ACF support forums?
I have registered a custom block with ACFs acf_register_block
. I have set a render_callback
to load a php template but would like to access any extra CSS classes which the user may have set in the admin.
Does WordPress provide a global like $block
(similar to $post
) or would I need to raise a question on the ACF support forums?
1 Answer
Reset to default 8Note that I don't have ACF PRO 5.8 which comes with the Block features, but I hope this answer helps.
If you look at the example here, you can retrieve the additional/custom CSS classes using props.attributes.className
; i.e. the classes are saved as an attribute named className
.
So with that in mind and based on acf_register_block()
(which as of writing, it redirects to acf_register_block_type()
), your render_callback
function would receive a $block
array (the block settings and attributes) as the first argument, and therefore you should be able to retrieve the additional CSS class(es) via $block['className']
as shown here — see the example under "Registering a block with callback".
本文标签: advanced custom fieldsHow to get quotAdditional CSS Classquot for ACF Gutenberg block
版权声明:本文标题:advanced custom fields - How to get "Additional CSS Class" for ACF Gutenberg block 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745511981a2153867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论