Display admin_notice error message form jQuery event

Thanks to Douglas.Sesar for pointing me in the right direction. Much appreciated! This is what I did… First put the following id in the title heading of the plugin. I am adding the admin message html (via jQuery) directly after this heading. <h1 id=”my-admin-message”>My Plugin Title</h1> My jQuery function: function fnDisplayAdminMessage(adminMessage, adminMessageColor) { jQuery.ajax({ type: … Read more

Fire jQuery function when post edit screen loads

You have your jQuery hooked too early. The jQuery library has not yet loaded when the load-(page) action is fired. Use admin_print_scripts to print inline scripts. That action comes after scripts are enqueued. Here’s your original code using admin_print_scripts: add_action( ‘admin_print_scripts’, function () { $status = “status-started”; if($status == ‘status-started’): ?> <script> jQuery(document).ready(function($) { /* … Read more

Dynamically update post title in admin page

The block editor is restoring back the title that was last saved (or typed manually into the textarea), so with the block editor, you can change the title dynamically using this code: wp.data.dispatch( ‘core/editor’ ).editPost( { title: ‘Title here’ } ) PS: You should make sure your JS file has the wp-editor, wp-edit-post or wp-data … Read more

Jquery no more loading, load-scripts.php not found (404)

I had this problem with a multisite setup. On my secondary site load-scripts.php returned a 404 error. the following line in wp-config.php fixed it for me: define( ‘CONCATENATE_SCRIPTS’, false ); # worked for me my .htaccess file: # BEGIN manual WordPress Multisite # The directives (lines) between `BEGIN WordPress` and `END WordPress` are # dynamically … Read more

How to get Ajax into a theme – without writing a plugin?

Put those add_action functions in your functions.php file too. If they’re in header.php, WordPress never registers them since header isn’t loaded in AJAX. Also, you don’t need that is_admin() check. The theme’s header will never load in admin. So, your functions file should look like this: add_action(‘wp_ajax_my_special_action’, ‘my_action_callback’); add_action(‘wp_ajax_nopriv_my_special_action’, ‘my_action_callback’); function my_action_callback() { $whatever = … Read more

Why do we include jQuery in the header?

Get rid of the plugin/theme that’s causing jQuery to load 🙂 jQuery is shipped with WordPress doesn’t mean that it’s loaded every time by default, it’s being loaded by a theme or plugin that you’re using. Look for a call to wp_enqueue_script 🙂 Good luck!

How to Add a .js file Only in one specific Page Dynamically to Head

Use conditional is_page() for loading script on specific page. Here Is The Modified Version of Your Function: //Load Scripts function load_scripts(){ wp_deregister_script(‘jquery’); // De-register Existing jquery wp_register_script(‘jquery’, ‘http://code.jquery.com/jquery.js’, ”, ”, true); wp_enqueue_script( ‘jquery’ ); wp_register_script(‘bootstrap-jquery’,get_template_directory_uri().’/assets/js/bootstrap.js’, array( ‘jquery’ ), ”, true); wp_enqueue_script( ‘bootstrap-jquery’ ); // register the script wp_register_script( ‘my-script’, ‘URL to Script’ ); // by … Read more

Deregister WordPress jquery on specific page

Hook to wp_enqueue_scripts. It will do the trick. Modified code is- if (!function_exists(‘modify_jquery’)) { function modify_jquery() { if (is_page(array(‘page 1’, ‘page 2’))) { wp_dequeue_script(‘jquery’); wp_deregister_script(‘jquery’); wp_register_script(‘jquery-custom’, ‘//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js’, false, ‘1.11.3’, ‘true’); wp_enqueue_script(‘jquery-custom’); } } } // add_action(‘init’, ‘modify_jquery’); add_action(‘wp_enqueue_scripts’, ‘modify_jquery’); Hope this is gonna help.