You can use wp_localize_script() to pass php variables to javascript. You create an array in php and then pass it to the function as the third parameter. It will come through as an object you name with the second parameter.
First, register the script.
wp_register_script( 'custom-name-js', plugins_url( 'assets/custom-js.php', __FILE__ ) );
Second, build your array and run wp_localize.
$my_array = array( 'description' => $description[0]->option_value );
wp_localize_script( 'custom-name-js', 'js_object_name', $my_array );
Finally, you enqueue your script.
wp_enqueue_script( 'custom-name-js' );
Then, in your js file, you will have a js object available named js_object_name (or whatever you pass as the second parameter to wp_localize_script) with a property of description.
js_object_name.description
Related Posts:
- Bootstrap and Custom CSS in custom plugin are being overwritten by theme
- wp_dequeue_script for a Plugin
- Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
- force enqueue script to be first in order of prominence
- When unit testing a plugin, does the plugin need to be in the wp-content/plugins directory of the WordPress tests install?
- How can I prevent a plugin from updating unless it’s minimum PHP version is met?
- Using require_once in a Plugin?
- Find out what is using PHP sessions in WordPress
- Bug in Stackoverflow styled badge system script
- How can I include PHP-Code to my post?
- how to display all posts Custom fields dynamically?
- Seriously stuck with some custom meta box/plugin stuff
- explanation for activate_plugin function in wordpress core
- WordPress PHP plugin – Settings page error
- Get product attribute for Simple product in WooCommerce
- wp_enqueue_scripts not working inside shortcode
- Creating an Exit Confirmation Popup
- Display a text message if the field is not found and not if found
- Reposition Woocommerce Message
- I don’t understand how this parameter works..?
- problems with wordpress and php version 5.3.3-1
- Prevent a plugin from being automatically activated
- WordPress takes too much time (100 seconds) to load – Front end and back end
- Saving changes in wp_editor
- Output array into one table cell
- how to change the verification url of pie register plugin of wordpress?
- wordpress plugin is not activating from widget
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- wp_get_post_terms is difference obj model than the one in rest api response
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- WpDataTables – View Image Directory
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- Server configuration for WordPress – Do I need install PHP-SSH extensions for WordPress on Fedora28?
- WordPress shows error related to allow_url_fopen
- Delete mobile menu button [closed]
- How to replace WordPress Media Upload Window with user’s device window?
- Using color picker in plugin, does input attribute order matter?
- Is there a loading priority for login_enqueue_scripts?
- WordPress custom taxonomy not showing
- My WordPress site when down after installing a plugin and now all I get is a simple white screen [closed]
- Pass user role to javascript code inside body
- Integrating boxtal PHP library into a custom WordPress Plugin
- How to get specific string/value from an array? php [closed]
- Background Music WP [closed]
- Customize Menu | Styling LESS/SCSS code formats
- Why is it important to check for isset and is_array before checking in_array in this example?
- ACF – How to set the menu order for the relationship field
- Custom search search does not work?
- How to call external functions from a PHP script in a WordPress plugin?
- Passing PHP Variables to AJAX Loaded Pages
- How to add custom function to pluggable.php
- Send Array from JS to php file then insert it in wp database through a plugin
- Offer Download Links for Product Images
- WooCommerce – new order email hook
- How to get the custom field value using SQL query
- How to list datas from database in a topic?
- Editing a coupon generating plugin
- Possible way of having multiple Gutenberg instances for a page?
- Woocommerce add products to cart
- How to hide an option from dropdown in filter module
- How use wp_insert_post and add og:custom tags?
- Display pagination in reservation Plugin and and Print table as pdf
- How to change “Read More” text?
- How to change a wordress plugin php code in my child’s functions.php file?
- What is the right way to populate a dropdown from MySql?
- Using id to show item
- WP Migrate DB Pro plugin cannot transfer Media files to remote server
- Woocommerce – Change variations output
- WordPress Plugin PHP Not Calling Function
- load plugin in code snippet
- Is admin section completely customizable in terms of styling?
- Problem in functions.php file
- How to echo meta_key in easy digital downloads receipt (Purchase Confirmation page)
- Plugin error “array_key_exists(): The first argument should be either a string or an integer” [closed]
- Creating Admin Submenu Page via Class Method
- I want add repository theme folder
- Migrating custom php we wrote from functions.php into a site-specific plugin
- What is the correct entry point for capturing coverage data
- How to create a dashboard for logged-in users with custom functionality? [closed]
- plugins_loaded action is not working properly
- Creating a user ‘add custom field’ section
- Cannot access variables within a widget
- How to Set Limit with WordPress Get Bookmarks Shortcode
- Postal address auto-complete on profile page
- avatar displays outside of targeted area
- WordPress Related Plugin – Adding an image
- ACF: Hide a div or template section when a custom field (in a field group) is empty
- How to delete remain data in WP database after deleting custom post via admin interface
- Populate Woocommerce order notes with custom field value
- Woocommerce Product Add-ons – Auto-select first option
- Strict Standards: Non-static method in sidebar generator
- Fast Tranfering my WordPress site to another server
- Duplicating wordpress install issue
- how to show selected options drop down menu values in attributes field in after saving post.php
- Can’t use updated variables in handle function
- How to get URL param for pagination in shortcode?
- wp_enqueue_script doesn’t load JS in plugin
- Is there any WordPress Plugin that provides video editing from front end side? [closed]
- Accessing Correct Database to Create REST API Endpoint
- How do I replace a logo image that’s hard-coded into a plugin’s logo.php file?