Plugin fails if jQuery isn't loaded in
-
Incrementing post views relies on a jQuery ajax script which is output to the header. However, if jQuery isn’t loaded into the header, this obviously throws an error.
You should know that it is common page speed optimization practice to put all javascript resources in the footer of the page – including jQuery. That is easily done in a theme with the following:
wp_deregister_script('jquery'); wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', null, null, true); wp_enqueue_script('jquery');
The second line tells WP to insert it into the footer rather than the header.
So, long story short, what I am simply asking you to do is to fix the plugin so it doesn’t rely on jQuery being loaded in the header. To me it seems like the obvious fix would be to not output your ajax script in the header, but in the footer, after all other scripts are done. Which is easily done by hooking into the wp_footer action and giving it a priority of 100 or so.
Also, please remove the HTML comments, like
<!-- WordPress Popular Posts ...
and so on. It’s fine for debugging, but they don’t belong in a production environment.
- The topic ‘Plugin fails if jQuery isn't loaded in’ is closed to new replies.