Handles to remove script calls from the pages that do not need JWPlayer.
-
In order to optimize my site for speed, I am trying to remove unnecessary script and style calls printed to my header in view-source. This plugin also seem to load scripts on every page, including mostly the pages that might not have a use for the plugin such as ‘archives’, ‘custom-post-types’ and ‘custom-templates’ etc.
These are two script calls printed in view-source I would like removed selectively from the pages that won’t need it.
<script type='text/javascript' src='https://p.jwpcdn.com/6/5/jwplayer.js?ver=3.6'></script> <script type="text/javascript">jwplayer.defaults = { "ph": 2 };</script> <script type="text/javascript"> if (typeof(jwp6AddLoadEvent) == 'undefined') { function jwp6AddLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } } </script>
I do not want to use yet another plugin for this purpose. I thought that this could be achieved with a few lines of code. I tried something that I learned here and tried in my functions.php and failed. I have tried many variations. Either I am not getting the right handle or my execution is wrong. Am a php newbie, please be kind and suggest me a correction.
function erase_jwp() { remove_action('wp_enqueue_scripts', array('JWP6_Plugin', 'insert_javascript')); wp_dequeue_script('jwplayer', JWP6_Plugin::player_url()); } if( is_page() ) { add_action('wp_head', 'erase_jwp', 6); }
P.S. : if (is_page()) {…} condition in the code is just for the start. If the handles are right it can always be set later.
https://www.ads-software.com/plugins/jw-player-plugin-for-wordpress/
- The topic ‘Handles to remove script calls from the pages that do not need JWPlayer.’ is closed to new replies.