Count Gutenberg blocks on the front-end?


Working on my 3rd project using Gutenberg blocks and have a requirement where I need to count the blocks in the loop so I can create, dynamically, a ‘jump to’ menu to various blocks, whatever order they are set as in the post/page.

I can count posts, ACF repeater fields etc in a loop – but is there a similar way to count the blocks, so I can set a conditional ‘If block 2, do x… if block 5 do this… etc’

Thanks in advance.

Phil Owen 1 year 2021-08-18T06:25:40-05:00 0 Answers 0 views 0

Leave an answer