Dynamic header and footer template inclusion: footer script not included

This is because the code uses require_once which only loads and runs the file once. require would fix the problem, but it would actually be better to use get_template_part() instead. This would allow you to use template filters, block templates, and child themes.

get_template_part( string $slug, string $name = null, array $args = array() ): void|false

https://developer.wordpress.org/reference/functions/get_template_part/