How to add code to `head` with WordPress 5.9 FSE (Full Site Editing)

Like adding Google Analytics code, and some other things surrounding the <head> tag, how’s all this done in FSE as there’s no header.php? Should I use functions.php for everything?

(Also can somebody make a fse tag in stackexchange?)

1 Answer
1

As far as I understand the wp_head and wp_footer actions should still work under FSE in WP 5.9+, through the template canvas PHP file that’s loaded through the locate_block_template(). That PHP file contains the basic HTML structure and there we find e.g. the familiar wp_head() and wp_footer() function calls that we usually had in the old footer.php and header.php theme files. The current block template HTML from get_the_block_template_html() is now displayed within the body tag from the template canvas.

So in FSE use e.g. the theme’s functions.php file or a custom plugin to add your wp_head and wp_footer actions in PHP.

Leave a Comment