AJAX Call Via Vanilla JavaScript In WordPress Plugin Development

Thanks Muhammad, Your solution is a fantastic working framework on which to base real world AJAX calls. I just added this code to the plugin main php file for a shortcode so I could use it in the Front End too. //For front end use in production add_shortcode(‘wp_testingPlugin_shortcode’, ‘wp_testingPlugin_shortcode’); function wp_testingPlugin_shortcode() { wp_enqueue_script( ‘ajax-script’, plugin_dir_url( … Read more

How to disable admin flyout menus?

It’s a bit of a workarround but here you go: function remove_flyout() { echo ‘<style type=”text/css”> .js #adminmenu .wp-submenu.sub-open { display: none; } </style>’; } add_action(‘admin_head’, ‘remove_flyout’); Put it in your functions.php

require.js to load javascript

Though WordPress already has a basic .js API (with register and enqueue script), I don’t see why you cannot use it in conjunction with require.js, at least at the modular level. From what I can tell (never used it) it only needs to be loaded, so you can, wp_enqueue_script( $handle, ‘…folder../require.js’, $deps, $ver, $in_footer ); … Read more

Add javascript when post is published

To enqueue scripts on the admin side, you should use the admin_enqueue_scripts hook. In this callback I check that are on the appropriate page (i.e. the page where you edit posts / post types), using the passed $hook argument. Optionally you can check if the post is of a specific type (in case this is … Read more

How to combine multiple CSS files and concatenate JavaScripts if WordPress recommends enqueuing them?

WordPress doesn’t really offer this functionality. You basically grab the array of enqueued scripts + styles and minify & concatenating them before they are output (using 3rd party script), of course you would want to cache this as well. This is quite complicated so I suggest instead: There are several plugins on wordpress.org that do … Read more