Trouble adding inline style after jQuery in the footer!

You are trying to load your inline js script after jQuery just by calling add_action( ‘wp_footer’, ‘myscript’ ); after wp_enqueue_script( ‘jquery’ ); But this will not load your myscript after jQuery. It is not how wp_footer and wp_enqueue_script works. wp_footer has a third argument named “priority”. add_action( ‘wp_footer’, ‘your_function’, 100 ); //100 is priority here. … Read more

jQuery in WordPress Plugin

You should place the .js file into your plugin directory (it can be root or any other folder like assets or js). To enqueue JS and CSS files in the front-end: function wp_357866_enqueue_frontend() { wp_enqueue_script(‘your-script’, get_template_directory_uri() . ‘/path/to/js/your-script.js’, array(), null, true); // You should set the last parameter to ‘true’ to load JS in the … Read more

Bad request 400 from custom ajax call

There’s only one reason you get a 400 error with admin-ajax.php: The wp_ajax_{$action} or wp_ajax_nopriv_{$action} action has not been hooked with an {$action} that matches the action data parameter sent with your request. So either your callback is not hooked, or you’re not sending the action correctly. Your code is making both errors. You are … Read more

Firebug says jQuery is loaded but $() and jQuery() are not defined

jQuery needs to be outside the wrapper like so: <script type=”text/javascript”> (function($) { $(document).ready(function() { alert(‘hello?’); }); })(jQuery); </script> Edit: A better way would be: jQuery(document).ready(function($) { // $() will work as an alias for jQuery() inside of this function }); Also make sure any inline script tags are AFTER your call to wp_head(); And … Read more

Enque Javascript in Footer?

The fifth parameter is $in_footer. You have left that out. Add that parameter, set it to true. wp_register_script( ‘jquery’, “http” . ($_SERVER[‘SERVER_PORT’] == 443 ? “s” : “”) . “://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js”, false, null, true ); But I echo the concern expressed by @Andrew in a comment. You can cause yourself trouble by deregistering/replacing the core libraries. … Read more

Form Security: nonce vs. jQuery

jQuery is a js library not a transport protocol, your data is sent via GET or POST, wether you use jquery or not. Think of it like this, sometimes it’s the user in the first frame, sometimes it’s javascript: Firstly nonces are not the same as sanitisation, they have different purposes Sanitisation is about verifying … Read more

Change CSS for logged in users

You need to use the body_class(): http://codex.wordpress.org/Function_Reference/body_class If you use the function body_class() you can set on your css like this: .example { display: none; } .logged-in .example { display: block }

Integrating jQuery Datatables with Editor into wordpress admin

Both DataTables Editor and WordPress are trying to use the same reserved parameter, ‘action’. WordPress is using $_REQUEST[‘action’] to route the request in admin-ajax.php line 86. DataTables Editor is using $_POST[‘action’] to tell the server-side processing script what action to apply ( insert / delete / update – see: https://editor.datatables.net/manual/server ) This would work fine … Read more