最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

advanced custom fields - How to get "Additional CSS Class" for ACF Gutenberg block

programmeradmin0浏览0评论

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?

Share Improve this question asked May 8, 2019 at 15:41 Alexander HolsgroveAlexander Holsgrove 1,9091 gold badge15 silver badges25 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 8

Note 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".

发布评论

评论列表(0)

  1. 暂无评论