I’m assuming the file you’re trying to display is located in your theme folder.
You can use get_template_directory_uri
to get the path of your currently activated theme’s root folder.
If you’re looking to support child themes get_stylesheet_directory_uri()
will look in the currently activated child theme’s folder if a child theme is in use.
If you must have your JavaScript in a seperate file, you should look into how to pass PHP variables to your JavaScript file with wp_localize_script()
. This is pretty straight forward.
I usually pass a variable called themeUrl
containing the URL of the theme folder and baseUrl
containing the base URL of my site to my JavaScript.
Related Posts:
- get_header() in backend – but keep JavaScript and CSS files
- Where is the Javascript attribute window._wpCustomHeaderSettings defined?
- adding script tag in head of specific pages
- How to add a class to a given element?
- How to make a word underline in Markdown
- Creating multiline strings in JavaScript
- Babel 6 regeneratorRuntime is not defined
- What is JSONP, and why was it created?
- React – uncaught TypeError: Cannot read property ‘setState’ of undefined
- await is only valid in async function
- Remove duplicate values from JS array [duplicate]
- How to read an external local JSON file in JavaScript?
- SyntaxError: Unexpected token o in JSON at position 1
- Remove duplicate values from JS array
- Add swipe left/right to web page, but use default swipe up/down
- Check if checkbox is checked with jQuery
- What does “res.render” do, and what does the html file look like?
- How to check if array is empty or does not exist?
- How to Create simple drag and Drop in angularjs
- stop all instances of node.js server
- Working with $scope.$emit and $scope.$on
- Using Node.js require vs. ES6 import/export
- How can jQuery deferred be used?
- Uncaught TypeError : cannot read property ‘replace’ of undefined In Grid
- Disable/enable an input with jQuery?
- How can I add a key/value pair to a JavaScript object?
- How do I change an HTML selected option using JavaScript?
- How to refresh a Page using react-route Link
- ChangeDate – Date Picker Bootstrap
- Is there a sleep function in JavaScript?
- scrollIntoView Scrolls just too far
- How to print a number with commas as thousands separators in JavaScript
- Convert Array to Object
- How to set the id attribute of a HTML element dynamically with angularjs (1.x)?
- Using $setValidity inside a Controller
- Combination of async function + await + setTimeout
- How to go from one page to another page using javascript?
- How to update array value javascript?
- Javascript setInterval not working
- Javascript Regular Expression Remove Spaces
- image.onload event and browser cache
- Simulate Keypress With jQuery
- react router v^4.0.0 Uncaught TypeError: Cannot read property ‘location’ of undefined
- What’s the fastest way to square a number in JavaScript?
- JavaScript: Create and save file
- Adding options to a
- How to use scientific notation in js?
- String.Format not work in TypeScript
- jQuery Ajax POST example with PHP
- Why am i receiving this jsfiddle error, document.write can be a form of eval
- jquery beforeunload when closing (not leaving) the page?
- Array Mapping in AngularJs
- How do I pass the this context to a function?
- HTML5 rich-text inside textarea
- Angular 4 setTimeout() with variable delay and wait
- JSON.parse unexpected token s
- How to fire an event on class change using jQuery?
- JavaScript code to stop form submission
- What do these three dots in React do?
- Change an image with onclick()
- javascript return true or return false when and how to use it?
- Uncaught SyntaxError: Unexpected token with JSON.parse
- Why is this simple AngularJS ng-show not working?
- How to open a Bootstrap modal window using jQuery?
- window.location.replace() not working to redirect browser
- “Cross origin requests are only supported for HTTP.” error when loading a local file
- How to destroy a JavaScript object?
- JavaScript isset() equivalent
- $http.get(…).success is not a function
- How can I convert an image into Base64 string using JavaScript?
- Is there a way to create interfaces in ES6 / Node 4?
- WordPress 5.5 – ReferenceError: commonL10n is not defined error
- wp_enqueue_script : how to change loading order of scripts?
- How to load translation in JavaScript?
- Is there a core Sortable component in Gutenberg?
- wp_register_script multiple identifiers?
- require.js to load javascript
- Is there an equivalent of the PHP function sanitize_key in Gutenberg?
- Add custom form to theme
- Setting HTML properties in a Gutenberg plugin using WordPress settings
- Is it mandatory to enqueue any kind of Javsacript?
- customize_preview_init: listening for any changes from Customizer preview area
- Add toggle button for mobile sub-menus
- Using webpack to add customizer live preview functionality – wp.customize is not a function
- why code javascript ,not repeat the loop main wordpress
- disable tags on wordpress text editor
- Change background image based on the hour [closed]
- is_front_page() variable not found
- How to modify the paths of js from twentytwelve theme?
- Get terms of a taxonomy using useSelect
- What to do about no-global-event-listener warning for “DOM is ready” function?
- How to render WP Rest-API Endpoints in a React.js Theme with Woocommerce
- customize-controls.js – extend api.previewer
- how can i send this to wp_head – escape problem
- Cannot read properties of undefined (reading ‘show_ui’) Error on WordPress Post Editor
- Script Loaded in WordPress but won’t run
- The script works only once by clicking on the opening and closing
- Add JavaScript-Library “Fitty” to WordPress
- Open image gallery on link click
- Include Facebook Javascript SDK In WordPress