You’ll need to get the screen id on the screen (or page) in question using get_current_screen()
get_current_screen()->id
Then, hook into it with the following:
function my_script_function() {
if ( strpos( get_current_screen()->id, 'screen_id' ) !== false ) {
wp_enqueue_script( 'my_javascript_handle', 'path/to/my/script.js', 'jquery', '1.0' );
}
}
add_action( 'admin_enqueue_scripts', 'my_script_function' );
This will enqueue your script properly in the WordPress system along with jQuery core (just in case it isn’t already there).
http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/ has a good overview of using jQuery in WordPress. Please note that by default though you can’t use $ to call jQuery as it is in safe mode (the article will show you how to change it from having to use jQuery.
Related Posts:
- Do I require the use of nonce?
- Problem with WordPress Ajax form
- Click loads template via ajax
- How to speed up admin-ajax.php in wordpress
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- How to test nonce with AJAX – Plugin development
- WordPress ajax doesn’t display object method on jQuery .change() function
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- adjust section according to country?
- dynamic dependent select dropdown
- How to disable controls in theme customizer?
- Using data sent via AJAX in multiple functions on a WP plugin
- Function won’t run onclick using Ajax
- Why i can’t get custom fields value or post ID via Ajax?
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Database entry removed on browser refresh, Ajax PHP jQuery
- Ajax filter with loadmore button
- Update $wpdb query with AJAX
- Input field duplicates on form submit by jQuery
- How to call a function from functions.php with ajax?
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Find the method which AJAX GET calls
- ajax form function error
- AJAX: WordPress filters inside $html do not work as intended
- getJSON response to PHP
- ajax problems on loading page [closed]
- Retrieve POST data from AJAX call
- Detect a focus on wp_editor
- WordPress Ajax always returns a 404 error
- problem with ajax and the path to the php page
- Can i check if user is doing any ajax request?
- simple wordpress ajax plugin not working when not logged in
- Update WordPress Custom Field with AJAX on cached page
- Targeting single page with JS
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Is the regular ajax request method safe or I should use admin-ajax.php?
- New Plugin Review
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- Returning a value from a PHP page
- Sending jsPDF documents to the server
- WooCommerce – Reset quantity input field when variation changes
- Checking for new message using AJAX and PHP. Server overload?
- jQuery not defined
- AJAX request status 200 but no actual “response”
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to call plugin function per site in a multisite?
- Save Search System
- Change “add to cart” button color based on Woocommerce product category [closed]
- Ajax request returns ‘Array’. How to output the actual results?
- Ajax load more button for comments wordpress
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- WordPress Custom field Colors
- Fancybox type popup window that’s not an iframe
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- How do I Import / Upload Files with jQuery AJAX?
- Is it save to use eval for a jQuery callback method coming from the database?
- WordPress plugin admin page – using WordPress function in linked php file
- Any ideas why I am getting “I’m getting “wp-admin/admin-ajax.php 401 (Unauthorized)”
- A $_POST should occur when submit form but is not?
- Shortcode to pull posts
- How to get post category list as select in front-end?
- Is there a hack for using is_page() within the function.php file?
- Submit form to db
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- How to load previous or next attachment with jquery ?
- Execute PHP code only with specific user role
- How to set value selected using select2 jquery plugin
- Disclaimer that will show every refresh of the page
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Using ACF Relationship field to set post type to draft or published status
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) through wp_admin_ajax.php
- Add Pre-Defined Value to Click Counter in WordPress
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- How can i avoid duplicate same post in wp?
- get_the_author_meta( ‘ID’ ) just return 1
- custom mailchimp form using HTTP API
- How to override theme’s public static function inside of a trait?
- Enqueue sripts and styles only if function is called
- AJAX to add to cart multiple products woocommerce
- WordPress ajax filter returning all posts when it should be filtering by category
- ajaxurl usage for a custom function
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- WordPress load javascript file if something… (after the page is loaded)
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- AJAX Filter WHILE Loop not working WordPress
- AJAX Returning Way Too Many Posts
- WordPress AJAX load post metadata in modal
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- wordpress ajax return 0
- Modify category archive page loop on functions.php
- Adding instant search to wordpress page
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- notify users when changed database
- WP Custom tables query
- How to use js variable to php in wordpress functions.php
- How to pass and validate nonce in custom REST routes