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
- Most efficient way to add javascript file to specific post and/or pages?
- Pass media upload value to input field
- JqueryUi Dialog giving Uncaught TypeError: this._addClass is not a function error
- WordPress Infinite Scroll without using any plugin
- WordPress Ajax always returns a 404 error
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- Understanding WordPress child theme custom JS loading
- How can I loop into two different DIVS without repeating the DIVs
- Display notification only once
- Access/update database with jQuery
- javaScript in section of WP API
- Using wp_localize_script to store the template url into a variable to use in JS
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Slide in Panel WordPress Post
- Sending jsPDF documents to the server
- Ajax return code 400
- Using shipped version of jquery
- 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
- jQuery not defined
- AJAX request status 200 but no actual “response”
- Use menu link or onClick to set a variable
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Populate dropdown with Child Pages based on Parent Page chosen
- 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
- Menu jumping when calling it via PHP
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- 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
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- 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
- Execute Jquery when a specific page in my plugin is loading
- 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
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- WordPress User Meta value variable into Google Gauge Chart
- 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
- Trying to add some custom text into WordPress Post title via function.php
- Using Javascript On Page – Header and Footer Now Missing
- AJAX to add to cart multiple products woocommerce
- 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
- How do I make comment-reply-button with that takes to comment reply form on click
- How to echo a PHP code into WooCommerce variation product?
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- Custom Post type Ajax search results
- include javascript Multiple files in wordpress through script.js
- wordpress all post filter by year
- Bootstrap Carousel Indicators Won’t Cycle On Custom WordPress Theme
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- Display text of price (minus 20%) on every product page in a sentence.
- Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
- How to create a radio button to alt between settings in wp_options table
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- Add a downloaded JS file to WordPress
- How to call javascript function (jquery) in a shortcode?
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- 500 (Internal Server Error) of external php file
- How can I correctly POST to a WordPress page?
- Dynamic Gallery
- Cannot get custom javascript to execute on page
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- JSON Object Value Show Undefine
- Adding jquery using php function
- notify users when changed database
- How to use js variable to php in wordpress functions.php
- Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
- hiddenQuestions.find is not a function
- get_post_meta returns on side but it doesn’t return on bottom of admin page