You need to do it the same way you’d get options, shortcodes, or any other WordPress value into JavaScript: You need to get them with PHP and pass them to the script with wp_localize_script()
:
wp_enqueue_script( 'my-script', asset_path( 'scripts/plugins.js' ), [], null, true );
wp_localize_script(
'my-script',
'myScript',
[
'galleryTransition' => get_theme_option( 'gallery_lightgallery_transition' ),
]
);
Just change my-script
and myScript
to something specific to your project.
Now you can access the value in your script via myScript.galleryTransition
.
Related Posts:
- New WP_Customize API – how does it work under the hood?
- In the new Theme Customizer API, how to send a value from the front back to the admin panel?
- How do I perform a “get” call to an external API, and then display the JSON results on a page in my WordPress site?
- Add Custom API Call to WP-Login.php
- Set Title from Custom Template
- Adding tags when creating new post
- custom email validation using javascript api with elementor pro and code snippets
- Get /users/me details from WordPress backend
- mailchimp integration on a custom footer
- Show WP content on different PHP Sites
- WordPress objects class reference
- Customizing gallery shortcode in 3.5
- Can You Export Theme Settings From WordPress Multisite?
- Adding Custom Fields to WordPress Comment Forms?
- How do you add pages on a staging server, and then move them over to production
- Any Hook Called When Post Becomes Published?
- Automatically wrap post image in div
- How Can A Widget With Only One Instance Be Defined?
- Getting $comments outside the comment template
- get_theme_mod(); returns nothing
- Theme Twenty Fifteen: Customize Color Scheme Customizer
- Find and replace domain name on the fly?
- What is the most idiomatic way to let clients edit phrases in HTML?
- Is it possible to set default values for custom fields in a custom post type while my plugin is being activated?
- How to change “Dashboard” text in wordpress
- WordPress Template not affecting the working, keeps defaulting to the index.php template
- Custom Widget form function common elements
- Image Editor does not affect custom sizes!
- How to fix the IE9/WordPress Twenty Ten Header Image Display Problem?
- Reinstall WordPress Without Losing Data
- Automatically add image caption with values from a post parent field?
- WP Northwind for Theme Development?
- list/consult Taxonomy only for the respective author/creator in dashbboard
- How to insert a sitemap within a subsite when using WordPress multisite
- How to check if site is created by wordpress? [duplicate]
- Enabling Additional CSS / custom-css
- Child Theme – how to add new widget on a specific place?
- Modify Gallery Output to render differently on a PAGE and a POST
- @font-face is not working in WordPress
- Add google org chart to wordpress page
- I’m using add_meta_box() but want to include TinyMCE editor *and* Media Uploads for each box
- How-To add Custom field in WordPress wp-ecommerce Categories?
- What changes we need to make to a theme so it can be installed as a MU Theme?
- Get Custom Logo Alt Text
- The function can not create a table on MariaDB server
- Child theme .css files are not overriding their parent .css files
- One WordPress Installation for 2 Domains
- result from custom filter admin table list backend does not work
- For a specific theme, how do I build a list of all the possible theme modification names?
- Post thumbnails not working in my new install of WP 3.1 with Twenty Ten theme
- Blog page problems
- Installing new theme on running site
- Switch between WordPress websites easy for an end user
- I’d like to be able to programatically setup a site to discourage crawling by search engines
- dbDelta not creating tables with composite keys
- WordPress broken after domain name change
- Daylight Saving Time adjustment
- How to Restore Deleted Post Not in Trash
- Hide content and functions from specific user roles
- Translating (WooCommerce) placeholder text
- Display content of metabox if filled in
- User profile Pick a premade Design/theme
- Recent activity query WordPress
- Echo the Last Child Taxonomy only (not parents)?
- Get All Results From Other Users That Share The Same Custom User Meta As Current User
- Can we set a redirection with dynamic content in url?
- website is not loading home page (moving from one server to another server)
- How to remove (…) from the post tilte on homepage?
- Swap home page based on user role, Elementor layout breaking
- Customized Blog/Latest Posts Page
- How can I setup a development environment which auto refresh page when code have changed [closed]
- Password Protection issue
- Trouble with custom login page
- I want to use a product thumbnail completely different than the product image
- How can I edit the WordPress menu link to allow fb: instead of http
- Fixed bottom menu on mobile doesn’t work on search included in Child Theme of Storefront
- Change Dashboard menu position?
- Get site ID from attachment url?
- how to edit or remove the dashboard footer message [duplicate]
- duplicate featured image functionality in custom meta box
- How to automatically pull an information from a form field onto an other page?
- How to create a custom menu for specific user
- How to submit form data in the same page in WordPress without reloading the page?
- Translate site in own text-language [closed]
- Move text from the side of image to below image [closed]
- Pull A Single Post Prior To Running wp_query
- How to work around the bug which prevents custom menus from being deleted?
- Custom terms in custom category taxonomy
- Customize TinyMCE Buttons
- Create a folder if it doesn’t already exist
- How to remove the tagline from the HTML ?
- Custom table or form
- How I can add blog in my magento site?
- Adding Telescope / Meteor App to existing WordPress site
- Help needed renaming custom post
- Instead of Custom CSS Theme CSS is loading
- Disable all Fonts that are Standard in WordPress and replacing them with a custom Font?
- Custom Menu (only showing direct cildren) ACF not showing
- Custom product sorting archive page
- Add custom information in editor summary