You can not mix js and php. It seems (sure) that your js script (that was embed in the document), has php in it. That can work if the code is embed in the document as the php tags are open and close correctly.
If you link to a js file, there is no way for it to understand php tags, function…
If you want to add safely some php in a js file, one way is to echo the script in the document (but you don’t want), other way is to enqueue the script and use wp_localize_script() to handle some php var.
If you can show some more code about script.php ?
Related Posts:
- How to use WordPress (PHP) functions in AngularJS partials files?
- Click loads template via ajax
- How to speed up admin-ajax.php in wordpress
- dynamic dependent select dropdown
- Ajax load more button for comments wordpress
- Why i can’t get custom fields value or post ID via Ajax?
- Update $wpdb query with AJAX
- How to call a function from functions.php with ajax?
- WordPress load javascript file if something… (after the page is loaded)
- Find the method which AJAX GET calls
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- Display notification only once
- Access/update database with jQuery
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- javaScript in section of WP API
- Using wp_localize_script to store the template url into a variable to use in JS
- JQuery not working on WordPress Admin page [closed]
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Adding tawk.to code just before body tag on functions.php file
- How do I fetch all comments per post via WP REST API?
- Slide in Panel WordPress Post
- Sending jsPDF documents to the server
- Ajax return code 400
- Show post in slider
- Using shipped version of jquery
- How to test nonce with AJAX – Plugin development
- How do I display a user’s previous orders as a select box option on a product?
- js file in root loading without
- WooCommerce – Reset quantity input field when variation changes
- class click counter save number
- Trigger popup in a php if/else statement
- Slider loading issue
- jQuery not defined
- AJAX request status 200 but no actual “response”
- Conditional Header in wordpress
- Use menu link or onClick to set a variable
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- How to select the contents in the text view textrea in wp_editor?
- Populate dropdown with Child Pages based on Parent Page chosen
- remove wp floating submenu in wp dashboard
- How to complete two other input fields, completed the first
- Pass Category Name, Description and Photo into variables to pass to jQuery
- JS file work only in index page
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Save Search System
- How can I get the values of my WordPress $wpdb query in Jquery?
- How to add a do_action on refreshing of WP customizer?
- Menu jumping when calling it via PHP
- Setting value of session with Ajax not working
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Add / Update Custom Fields After Select Pictures in Media Window
- Post repeating with infinite scroll
- Fancybox type popup window that’s not an iframe
- How to disable controls in theme customizer?
- How do I Import / Upload Files with jQuery AJAX?
- Noscript not working as it should in wordpress site
- WordPress Ajax Call inserting data but success response false
- Error – ‘create_function is deprecated’ [closed]
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- Tell WP register script to load a script only when the entire page is loaded
- Is it save to use eval for a jQuery callback method coming from the database?
- Jquery window.send_to_editor function
- Function won’t run onclick using Ajax
- Theme not calling Jquery properly
- How to add drag and drop functionalities to a div inside option panel
- How to make jquery count down timer function manually editable
- How to reference PHP in Javascript
- JS file is not loading when i put wp_head() and wp_footer
- Accessing an API with jQuery and AJAX
- Execute Jquery when a specific page in my plugin is loading
- Replacing WordPress Icons (menu,icons32, etc)?
- Covert WordPress Blogname into JQuery
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Execute PHP code only with specific user role
- How to set value selected using select2 jquery plugin
- Hot to check if new posts have been published since page load and notify online users?
- Time Delay a URL Redirect for Specific Page
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Database entry removed on browser refresh, Ajax PHP jQuery
- WordPress User Meta value variable into Google Gauge Chart
- How to send a php var to jQuery Ajax call with two different file
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Adding HTML Code to Replace Text in PHP
- Add other class content with reference class value
- Gutenberg block don’t save rich text content
- Ajax filter with loadmore button
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- Outputting post content to jQuery .html() string
- How to use wp_ajax_set_post_thumbnail?
- Trying to add some custom text into WordPress Post title via function.php
- Using Javascript On Page – Header and Footer Now Missing
- Woocommerce – if selected attribute term equals
- AJAX to add to cart multiple products woocommerce
- Using wp_editor() when not logged stopped working
- Adding extra data to shortcode attributes and pass it to JS with wp_localize_script
- Show the subcategory name based on current product
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- JQuery modal not loading video on popup, only displaying it after multiple reopenings