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
- How to remove search bar from a wordpress theme? [closed]
- How to: Update live sites theme from version control repo via plugin or library? [closed]
- Adding items to page template dropdown on Page Edit Screen
- How to programmatically bring back “excerpts” field in post editor in WP 3.1+
- Get background color for Live Preview with Theme Customization API?
- Add a theme via symlink
- Alterntives to BEM syntax that comply with WordPress coding standards? [closed]
- How to determine which registered sidebar area a custom widget is loaded into
- Administration Pages Styling
- How can i convert the figma design into wordpress [closed]
- A custom theme with support for multiple layouts
- How to show a dynamic_sidebar if main content content’s height is > a set amount?
- Creating Theme Options Page
- What is the best way to organize template parts?
- wp_enqueue_script outside functions.php file?
- How can I make my options in an array and store theme in WP options one DB row?
- Differences between developing custom themes for wordpress.com and wordpress.org?
- Easy to develop on a URL that is changed for production?
- How to control on which pages the Aldehyde theme’s main slider is shown?
- WordPress stylesheet isn’t being added
- How to detect and display a page only for IE?
- Change image size depending on page
- What and where are the WordPress core-bundled scripts?
- How do I get from search_theme_directories() to the $stylesheet (name) for switch_theme()
- Tabbed theme options query about add_settings_section callback function
- How to know if I am on 1st page
- I don’t know why categories are showing below post
- WordPress Custom font not found
- How do I control the header space in non-front pages in Twenty Seventeen?
- Customizer API way function is_customize_preview() works only in main page?
- Advantages/Disadvantages Using Theme Editor Instead of Pages
- Magnific Popup – Add Caption to Images
- paragraph format in WYSIWYG on a custom theme?
- unable to display the image meta value as background
- editor style css and page template with and without sidebar
- 3 x 3 grid of posts on the home page
- The normal loop with different styles doesn’t work in search.php
- Pass custom css class to add_menu_page
- How to force unlink on attached/inserted images?
- How to create sub-menu in “Allure Real Estate Theme for Placester”?
- Bootstrap 4 mobile menu not working for WordPress Development
- How do I send out an update for my custom wordpress theme?