Remove output script when no buttons are added on page
-
Hi,
To make the configuration perfect with AddThis plugin, I dont want the javascript code to be generated when we dont need it.
No matter what, the javascript is always output in the footer, even if we uncheck the admin options and not using the widget, remove content filter etc etc and so on.
The solution is to access the class
$AddThis_addjs_sharing_button_plugin
and remove an action. But I cant reach the class.Not working:
global $AddThis_addjs_sharing_button_plugin; remove_action('wp_footer', array($AddThis_addjs_sharing_button_plugin, 'output_script') );
Not working:
$addThisSharingButtonsPluginObject = new AddThisWordPressSharingButtonsPlugin(); $cmsConnector = new AddThisWordPressConnector($addThisSharingButtonsPluginObject); $addThisConfigs = new AddThisConfigs($cmsConnector); $AddThis_addjs_sharing_button_plugin = new AddThis_addjs_sharing_button_plugin($addThisConfigs, $cmsConnector); remove_action('wp_footer', array($AddThis_addjs_sharing_button_plugin, 'output_script') );
WORKING:
global $wp_filter; $hook_name = 'wp_footer'; $class_name ='AddThis_addjs_sharing_button_plugin'; $method_name = 'output_script'; $priority = 10; if(!isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority])) return false; foreach( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) { if ( isset($filter_array['function']) && is_array($filter_array['function']) ) { if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name ) { unset($wp_filter[$hook_name][$priority][$unique_id]); } } }
So how can I do this the clean way?
- The topic ‘Remove output script when no buttons are added on page’ is closed to new replies.