Why are you not using the built-in enqueue_script
function? Simply put your custom jQuery code into a file called custom.js, save it into your plugin or theme folder, then enqueue it with jQuery as a dependency:
<?php
function custom_scripts() {
if (is_admin()){
wp_enqueue_script(
'customjs',
get_template_directory_uri() . '/js/custom.js',
array('jquery')
);
}
}
add_action('wp_enqueue_scripts', 'custom_scripts');
You’ll need to change the get_template_directory_uri()
function to get the proper path of your plugin, but that’s basically it.
EDIT: You WANTED it in the admin. Missed that.
Related Posts:
- JQuery not working on WordPress Admin page [closed]
- Most efficient way to add javascript file to specific post and/or pages?
- Pass media upload value to input field
- Combine CSS and JS files from plugins
- JqueryUi Dialog giving Uncaught TypeError: this._addClass is not a function error
- WordPress Ajax always returns a 404 error
- Jquery no more loading, load-scripts.php not found (404)
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- How to use WordPress (PHP) functions in AngularJS partials files?
- Nice scroll to wordpress
- Using an Image Slider twice on the same page
- Click loads template via ajax
- Display notification only once
- Access/update database with jQuery
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Using wp_localize_script to store the template url into a variable to use in JS
- How to speed up admin-ajax.php in wordpress
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Sending jsPDF documents to the server
- Ajax return code 400
- Show post in slider
- Using shipped version of jquery
- How to test nonce with AJAX – Plugin development
- js file in root loading without
- class click counter save number
- Slider loading issue
- AJAX request status 200 but no actual “response”
- How to select the contents in the text view textrea in wp_editor?
- remove wp floating submenu in wp dashboard
- Save Search System
- dynamic dependent select dropdown
- Ajax load more button for comments wordpress
- How to add a do_action on refreshing of WP customizer?
- Menu jumping when calling it via PHP
- Setting value of session with Ajax not working
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Add / Update Custom Fields After Select Pictures in Media Window
- Post repeating with infinite scroll
- Fancybox type popup window that’s not an iframe
- How do I Import / Upload Files with jQuery AJAX?
- WordPress Ajax Call inserting data but success response false
- Error – ‘create_function is deprecated’ [closed]
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- Is it save to use eval for a jQuery callback method coming from the database?
- Jquery window.send_to_editor function
- How to add drag and drop functionalities to a div inside option panel
- AJAX wp_insert_user WORKS but responds with “The site is not enabled”
- Why i can’t get custom fields value or post ID via Ajax?
- JS file is not loading when i put wp_head() and wp_footer
- Accessing an API with jQuery and AJAX
- Replacing WordPress Icons (menu,icons32, etc)?
- Covert WordPress Blogname into JQuery
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Hot to check if new posts have been published since page load and notify online users?
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Search bar for wp menu
- Add other class content with reference class value
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- How to use wp_ajax_set_post_thumbnail?
- Hide Approved status for certain users in users list
- Update $wpdb query with AJAX
- AJAX to add to cart multiple products woocommerce
- Using wp_editor() when not logged stopped working
- Show the subcategory name based on current product
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- Move Jquery.js to Footer
- How to echo a PHP code into WooCommerce variation product?
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- How to call a function from functions.php with ajax?
- WordPress load javascript file if something… (after the page is loaded)
- include javascript Multiple files in wordpress through script.js
- number of posts with “Load More”
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Bootstrap Carousel Indicators Won’t Cycle On Custom WordPress Theme
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- Find the method which AJAX GET calls
- Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
- How to create a radio button to alt between settings in wp_options table
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- Add a downloaded JS file to WordPress
- Slider from different widgets
- How to call javascript function (jquery) in a shortcode?
- 500 (Internal Server Error) of external php file
- How can I correctly POST to a WordPress page?
- Why this plugin is not working?
- Dynamic Gallery
- Trying to fix multiple category drop down
- Cannot get custom javascript to execute on page
- Add specific phrase after every product title including the discounted price? [closed]
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- JSON Object Value Show Undefine
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- notify users when changed database
- get_post_meta returns on side but it doesn’t return on bottom of admin page
- Stumped – Ajax Response Returns 0
- populate form fields in a loop with ajax
- AJAX Filter WHILE Loop not working WordPress