As I understand PHP and WordPress syntax will throw 404 error if it is within a functions.php file.
Can be managed WordPress hook like an example within hook directory (not a plugin)?
I have added PHP inside a functions file:
Example:
if you’re seeing the PHP content itself along with a 404 error. This suggests that WordPress isn’t processing the PHP file but is trying to serve it as plain content, and the server isn’t set up to do so for that request.
Create a custom function to alter the behavior of your script.