What is the best practice for customizing a plugin’s JavaScript/jQuery?

If a Plugin is coded properly, it will: Use core-bundled jQuery, and any other core-bundled script, rather than bundling/using custom versions of such scripts enqueue its scripts, via wp_enqueue_script(), hooked into an appropriate hook, via an explicit function So, for such a Plugin: You won’t need to worry about customizing/overriding core-bundled scripts, since the Theme … Read more

jQuery plugin only in one page/post

If you only want to use the library “jquery.typist” on one page you could just add it by the conditional is_page() but if you want to use it on more than one page you should just minifyi all your js-files into a single one and compress it and cache it. It is better to use … Read more

Defer Parsing of Scripts

At the first glance, you sure have a lot of Javascript included in your Website. You can take a few steps towards reducing/speeding up this section. Before I start, please let me remind you that the PageSpeed by Google is not an actual tool to keasure how fast a website loads, it is more a … Read more

Force wp_enqueue_scripts to the HEADER?

The normal behavior of wp_enqueue_script is to put the script output into the head section, the parameter $in_footer is optional and defaults to false. So, you can load jQuery with your plugin into the head and, assumed your dealing with well programmed themes/plugins, it won’t load again, because wp_enqueue_script prevents this by default – additional … Read more

Getting a div content of a post in wordpress?

Using DOMDocument and DOMXPath you could try this. <?php while (have_posts()) : the_post(); ob_start(); // run the_content() through the Output Buffer the_content(); $html = ob_get_clean(); // Store the formatted HTML $content = new DomDocument(); // Create a new DOMDocument Object to work with our HTML $content->loadHTML( $html ); // Load the $html into the new … Read more

Access Customizer’s DOM – jQuery

The customizer preview is in a different window than the window that contains the customizer controls. Specifically, the customizer preview is contained inside of an iframe. So that is why you cannot directly use jQuery to select elements. One way to work around this is to use parent.jQuery from the preview, but this is not … Read more

Load more AJAX on WP Query

if you want to use ajax in wordpress you must have to follow these step: 1) first make your js file like main.js. 2) localize it in functions.php with wp_localize_script(). wp_enqueue_script( ‘main.js’, get_template_directory_uri().’/js/main.js’, array( ‘jquery’ ) ); wp_localize_script( ‘main.js’, ‘ajax_object’, array(‘ajax_url’ => admin_url(‘admin-ajax.php’)) ); 3) make your javascript or jquery code to run your query … Read more

Removing jQuery migrate and working with dependencies

First part… OK, so in your theme/plugin you have: wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘scripts’, get_template_directory_uri() . ‘/js/scripts.min.js’, array( ‘jquery’ ) ); The first line, enqueuing jquery isn’t necessary – you put jquery as dependency in second line, so it will be included anyway. These lines inform WP that you want to enqueue given file as … Read more