theme development – What is the “correct” way to add hooks or similar PHP behavior to a blocktheme?


I’m building a new site and I wanted to build my theme from scratch. However, the WordPress ecosystem is moving more towards blocks and blockthemes. As far as I can tell, it is possible to put hooks (do_action(), apply_filters()) into a block theme, but it seems like I’d be making a weird hybrid. I don’t want to only use HTML (including CSS and JS) when I build some of the pages; I really want to have places that I can hook PHP commands into. It’s probably more correct to say that I have to use PHP for many of the site features and hooks are a great way to do it.

I haven’t seen any hooks inside of blockthemes, so is there a good convention to follow for putting them in one? Or are blockthemes meant to avoid hooks altogether, in favor of blocks and shortcodes? Let’s say that I wanted to have a banner at the top of the home page, but underneath the header that changes according to the user roles and current date (I’ve done that before by hooking into the top of the theme page). What is the best way to implement that in a block theme?

Cubic Infinity 2 months 2022-06-06T18:57:15-05:00 0 Answers 0 views 0

Leave an answer