One way to add JavsScript in functions.phhp is to put the JavaScript into a JS file an enqueue it. With wp_enqueue_script()
.
js/mynicecode.js
var x = myFunction(60000, 5.15464, 100); function myFunction(a, b, c) { return Math.round (a * b / c);
in functions.php
function my_load_scripts($hook) {
wp_enqueue_script( 'mynicecode_js', plugins_url( 'js/mynicecode.js', __FILE__ ), array());
}
add_action('wp_enqueue_scripts', 'my_load_scripts');
Related Posts:
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- How can I see all the actions attached to an “add_action” hook?
- How to include code only on specific pages?
- Customizing subject in comment notification e-mails
- WP showing “warning: call_user_func_array()”, What to do?
- How to call plugin path in JS?
- WordPress Hook that will run when media file deleted
- How can I make content disappear when a user logs in?
- How to save Clicks of a download link button while it doesn’t matter if we refresh the page or again login/logout
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- How to use wp-ajax in wp-cron
- White text on white background in TinyMCE when wp_editor is called in WP 3.9
- Is it possible to filter the wp_footer() scripts, read the content, and insert them inline?
- How can I make the “Preview Post” button save and preview in the same window?
- Creating an Exit Confirmation Popup
- Difference between register_block_type & wp.blocks.registerBlockType
- Reposition Woocommerce Message
- How to initialize something in unit test before the init hook being called?
- Pass a php string to a javascript variable
- add mediaelement.js plugins into WordPress video player control bar
- Shortcode button dosent work for all posts. Work for first post only
- Prevent a plugin from being automatically activated
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- Is there an earlier hook than login_head or login_enqueue_scripts?
- wordpress site | All-in-one-cufon IE Issue
- How to get the element ID from new menu list that added with add_filter()?
- Override Plugin Script Fucnction in WordPress
- wp_get_post_terms is difference obj model than the one in rest api response
- add image crop function like in wp customizer
- How to edit content before post update
- How to insert HTML/JavaScript form into WordPress page? [closed]
- How to get my plug-in, wrote in php, to refresh on its own every 5 minutes?
- Using TinyMCE in plugin?
- Using window.onload with Ubermenu
- Redirect to another page using contact form 7? [closed]
- JavaScript in a PHP plugin
- Deactivate JS Script in Plugin Shortcode
- wordpress add_action() issue in ajax call
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Are there action hooks for comments?
- Pass user role to javascript code inside body
- get specific value of a array | PHP
- How do I add $_SESSION[”] to my wordpress page?
- How to get specific string/value from an array? php [closed]
- coding a WordPress AJAX Form using PHP to check if User is Logged Out and Show error
- Save user total active time after login in wordpress [closed]
- WordPress: Add custom add_filter for custom functions
- Background Music WP [closed]
- How to use custom Javascript code inside a plugin?
- Adding a simple Javascript file with a plugin
- Social share buttons text shows up on post excerpts
- Plugin Admin panel checkbox unchecked after submit
- uncaught TypeError: Cannot read properties of null (reading ‘classList’) custom plugin
- Custom Plugin scripts from admin working in frontend
- Code for unique user visit count on every page WordPress
- Ajax call not working in wordpress through a plugin
- Send Array from JS to php file then insert it in wp database through a plugin
- Use a hook or filter, or overwrite this Gamipress function?
- WordPress Custom Hook with Class method
- Possible way of having multiple Gutenberg instances for a page?
- Woocommerce add products to cart
- Calling PHP function with AJAX
- Why does my custom plugin only function correctly once per page?
- How to get a specific string from a url
- Hooking into the HTML header container
- How can I create a secure file download in WordPress?
- Use AJAX to fetch Current Post Thumbnail for WordPress when Uploaded throughMedia Uploader Frontend
- Problem with wordpress has_action() function
- Multiple image selection custom widget
- Custom Field used to allow a Free Story; no longer works
- Create a form and have custom menu display based on user answers?
- Woocommerce – Change variations output
- Speeding up WordPress on a Local Network
- Conditional Fields depending on checkboxes
- Caching of combined CSS and JS fails because of losing MIME types through combining by PHP
- What is the correct entry point for capturing coverage data
- Number format in thousands on highcharts in wpdatatable plugin
- Embed Javascript code to registered users only
- How to limit each front-end user to view just his own uploaded files on Amazon S3?
- How to create a dashboard for logged-in users with custom functionality? [closed]
- Creating a user ‘add custom field’ section
- Media Playlist Plugin
- Plugin Hook: Get posts
- How to set up php,javascript and css to allow for our finished product to be displayed within a page?
- How do I convince this button to do something when it is clicked?
- Can’t insert files in other inputs
- How do I output user_registered time in my correct timezone?
- How to tweak a plugin without preventing it from updating
- How to create post comparison in wordpress
- Adding a script & php to functions.php
- 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
- Refresh server side rendered block in Gutenberg without changing attributes or its content
- How do I call an action hook into wp_ajax hook callback function
- shortcode doesn’t work
- Where to hook my plugin’s action
- GeoMashup plugin: how to customize cluster markers / icons? [closed]
- Adding javascript to header of MetroMagazine theme
- how to restore wordpress backup(.rar) manually?
- Two sites one PC