WordPress hook but PHP file with an error 404

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:

  wp_enqueue_script('hook',get_template_directory_uri() . '/javascript1.php','','',true);

Why is now showing a PHP content with an error 404 or it can be solved a hook as PHP?

Have you checked the path specified in get_template_directory_uri() . '/javascript1.php' ? Is the 'javascript

PHP is a server side. It contains JavaScript, HTML, PHP. It seems WP does not allow PHP inside

wp_enqueue_script

Is this true or do you have an 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.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.