Enqueue your script and use wp_localize_script
to pass data.
function wpd_scripts() {
wp_enqueue_script(
'wpd_script',
get_stylesheet_directory_uri() . '/js/script.js',
null,
null,
false
);
wp_localize_script(
'wpd_script',
'WPD',
array(
'stylesheet_dir' => get_stylesheet_directory_uri()
)
);
}
add_action( 'wp_enqueue_scripts', 'wpd_scripts' );
You can then use WPD.stylesheet_dir
in your script to get the value you set in PHP.
var marker_url = WPD.stylesheet_dir + '/assest/imgs/map/cd-icon-location.png';
Related Posts:
- MapPress Easy Google Map in Jquery Tabs Problem
- pass object/JSON to wp_localize_script
- Google Maps not displaying in wordpress using Google Maps Javascript API
- How to alter the text of the post “Excerpt” box label in WordPress post editor?
- What is the best practice for customizing a plugin’s JavaScript/jQuery?
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- How to Change CSS Variable value in Theme Customizer Live Preview
- wp_enqueue_script being ignored in custom theme
- Getting jquery to work with custom theme
- Adding wp_enqueue_media(); causes problem
- How to correctly add JQuery in a WP theme?
- Toggle Sidebar Display
- Including Javascript options
- Unhook jQuery from WooCommerce via `functions.php`? [closed]
- Fancy-box Esay wordpress plugin fails to work on Multilingual site
- WP 3.1 upgrade breaks AutoFocus+ theme
- Difficulty loading jQuery with wp_enqueue_script
- jQuery not available to other scripts
- My javascript jquery won’t work?
- Implementing FancyBox
- How to: JQuery multiple wordpress media uploader buttons in the same options page?
- Post thumbnail to append post content via ajax click event
- Would to use AJAX to get an option from the database and use it in a jquery setup or is there an alternative to consider?
- Using page-id-{ID} from body_class() in local dev, versus live staging
- My jQuery is enqueued properly. So why isn’t it working?
- Custom theme, contact form 7 & fast secure form doesn’t work
- Javascipt issue on custom theme
- How to make javascript work on theme options page
- JQuery undefined and Stylesheet loads in bottom along with js files
- Weirdness in jQuery supplied with WordPress
- jQuery from parent theme loaded with many other scripts in a single min.js file
- Trouble in enquing all js files under certain directory
- How do I implement jPanelMenu?
- loading javascript after jquery is loaded
- I don’t think WordPress is loading jquery or bootstrap js
- how can i remove js file from my footer in wordpress
- How to properly use AWS SES for a contact form?
- Embedding CodePen Calorie Script – jquery error
- How to load jQuery with Ajax in WP version 5.3.2?
- How to enqueue scripts properly with ES6 webpack?
- Infinite scroll without plugin using ajax
- change background image on scroll
- how to add jquery to wordpress
- jQuery conflict in WordPress, works fine in HTML
- How would I get this to work – send to post from thick box
- FitVid not working for iframes on particular theme install
- Enable WP to accept standard jQuery code embeding between the tags [duplicate]
- WordPress custom jquery not found
- Passing a location-dependent array via wp_localize_script within a shortcode
- enqueue script if page is not equal to
- Set start page depending on screen width [closed]
- WordPress Subpages Fancybox Trouble
- Theme now uses require.js and enqueue script no longer works
- can’t add EVENT LISTENER to a element
- jQuery Snippet Not Working on WordPress Site [closed]
- WP Customizer get control value on change
- Execute javscript when theme customizer loads (autosave issue)
- WordPress Includes mejs 404 error
- WordPress and Semantic UI
- hide theme files for admin beneath root
- Help with Core Mods
- Warning: This page allows direct access to your site settings. You can break things here. Please be cautious!
- How to change PHP variables with AJAX request in WordPress
- Building a custom menu or use a plugin?
- Displaying front side empty with one file attached problem
- Bootstrap slider not working
- When I save changes for css and js in my WP localhost env windows 10 the changes don’t take effects immediately!
- Problems with cart and pages on _s theme
- Is it possible to show sort page excerpt in search.php
- Customizer API Multi Sections in single Panel
- 3 Level Menu Navigation (3rd Level not displaying)
- Sidebar not displaying (theme development)
- Next and previous post link shows error in first and last post
- Custom pages with html in wordpress editor vs. writing it all directly in the php template files?
- How to dynamically set a background image with the customizer without putting the css as an inline-style
- WordPress theme options checkbox default checked state
- WordPress theme files Organization
- add diffrent images to a page
- Custom themes that won’t work when theme is changed
- add page items to index
- WordPress theme settings not saving
- create loop for the_content()
- Alter shop page lay-out in OceanWP theme
- how to change footer content for certain pages only
- only the first post is shown
- Is the date when a theme was activated stored?
- Page For Specific Posts
- function ‘theme_settings_page’ not found
- wordpress can’t find single-project page
- Default customizer colors aren’t displayed outside of the preview
- Image cropping isn’t working correctly when using Offload Media
- How toprint informations in footer
- Theme functions don’t work as expected in partial included via get_template_part() after custom query using Ajax [duplicate]
- How to implement pagination in category.php template
- Can any IDE (eg PHPStorm, VS Code) correctly show functions added via require get_template_directory() string results?
- How can I set multi archive page template on same time for only one custom post type?
- Array for WordPress Avatar Size and Class
- Use instead of for wp_nav_menu()
- Find out the reason that the Styles and scripts in the theme are loading properly in localhost but Not in server after deploying
- Exclude categories from wp query not working