What you can do is pass the variable from outside that .js
file, like this:
// index.php <div class="row"> <div class="small-12 columns"> page content </div> </div> <script>var test = '<?php echo $variable; ?>';</script>
and then reference that variable the same as if you defined it within that .js
file (mind the potential scope issue).
Related Posts:
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- is there something like isset of php in javascript/jQuery?
- How do I refresh a DIV content?
- Only on Firefox “Loading failed for the script with source”
- Ajax success function
- AJAX not Working with php as supposed
- Open image gallery on link click
- Sending jsPDF documents to the server
- Ajax return code 400
- Pass a php string to a javascript variable
- Show post in slider
- Using shipped version of jquery
- How to test nonce with AJAX – Plugin development
- Adding JavaScript to a WordPress website
- js file in root loading without
- class click counter save number
- Slider loading issue
- AJAX request status 200 but no actual “response”
- How to select the contents in the text view textrea in wp_editor?
- wordpress site | All-in-one-cufon IE Issue
- Jquery function working in Chrome Console but not in the code [closed]
- How can I get my Calculate Contact Form 7 field to update with jQuery? [closed]
- Contact Form 7 – Uncaught TypeError: wpcf7.initForm is not a function [closed]
- contact form 7 repeatable fields calculations [closed]
- List of JS Events for Widgets?
- How to set callback to execute after all the tinyMCE editors have been initialized?
- Save Search System
- dynamic dependent select dropdown
- Ajax load more button for comments wordpress
- 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
- Using window.onload with Ubermenu
- How do I Import / Upload Files with jQuery AJAX?
- WordPress Ajax Call inserting data but success response false
- JQuery not loading
- is_page_template() written in jquery/javascript
- Error – ‘create_function is deprecated’ [closed]
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- Cannot use characters ” in jQuery script in WordPress
- Is it save to use eval for a jQuery callback method coming from the database?
- Jquery window.send_to_editor function
- wordpress add_action() issue in ajax call
- How do I make my wordpress post appear in a mouse hover preview?
- How to add drag and drop functionalities to a div inside option panel
- On click load iframe [closed]
- Uncaught ReferenceError: jQuery is not defined – although jQuery is loaded [closed]
- Uncaught TypeError: jQuery(…).slider is not a function
- Why i can’t get custom fields value or post ID via Ajax?
- Getting a variable inside foreach from PHP to JS after localization
- JS file is not loading when i put wp_head() and wp_footer
- Accessing an API with jQuery and AJAX
- Replacing WordPress Icons (menu,icons32, etc)?
- Covert WordPress Blogname into JQuery
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Change each text after 4 second and each image after 2 second
- Hot to check if new posts have been published since page load and notify online users?
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- How to set javascript options for select2 in PHP array of plugin
- Putting custom html/js page into Elementor as it’s own block
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- wp post_tag change minlength
- How to load Javascript code or functions.php later in a child theme?
- How to locate the js code and php code for certain function?
- Can’t get rid of JQMIGRATE: Migrate is installed, version 3.3.2. Manually updated all the libralies and site. 5.8.2
- Script only works on wordpress home page & only when Jqurery is aded using
- how to prevent added meta box from being injected with style=”position: fixed; top: 56px;” at scroll down
- Add other class content with reference class value
- internal anchor links no longer working after upgrade
- How to run Javascript popup modal in a loop?
- Get the ID of a page in Parent combobox in editor
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- How to get a specific string from a url
- “jQuery Not Defined” Error When Connecting to PayPal
- Fade-in Fade-out doesn’t work in WordPress
- How to use wp_ajax_set_post_thumbnail?
- Error on clicking ‘Screen Options’ tab only at Products-related editor screen(s) and for specific user
- Can’t Listen to KeyDown in TInyMCE Iframe (jQuery) and Pass it to Parent HTML FORM
- Remove escape characters from JSON string pulled from a database
- Update $wpdb query with AJAX
- Select parent from child class name then add another class name to the parent
- AJAX to add to cart multiple products woocommerce
- Using wp_editor() when not logged stopped working
- Show the subcategory name based on current product
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- Move Jquery.js to Footer
- 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?
- How to call a function from functions.php with ajax?
- WordPress load javascript file if something… (after the page is loaded)
- include javascript Multiple files in wordpress through script.js
- number of posts with “Load More”
- Bootstrap Carousel Indicators Won’t Cycle On Custom WordPress Theme
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]