Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Last active December 9, 2022 14:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webtoffee-git/6b2fa352a5207477091a674524c10412 to your computer and use it in GitHub Desktop.
Save webtoffee-git/6b2fa352a5207477091a674524c10412 to your computer and use it in GitHub Desktop.
Add more scripts to the default script blocker list using WebToffee GDPR Cookie Consent plugin
function scripts_list() {
$scripts = array(
array(
'id' => 'googletranslator',
'label' => 'GoogleTranslator',
'key' => array('translate.google.com/translate_a/element.js'),
'category' => 'analytics',
'status' => 'yes'
),
);
return $scripts;
}
add_filter('cli_extend_script_blocker', 'scripts_list', 10, 1);
@drkdw
Copy link

drkdw commented Dec 9, 2022

Isn't it better to wrap class_exists around it?

function scripts_list() {
	if ( class_exists( 'Cookie_Law_Info' ) ) {
		$scripts = array(
			array(
				'id'       => 'googletranslator',
				'label'    => 'GoogleTranslator',
				'key'      => array( 'translate.google.com/translate_a/element.js' ),
				'category' => 'analytics',
				'status'   => 'yes',
			),
		);
		return $scripts;
	}
}
add_filter( 'cli_extend_script_blocker', 'scripts_list', 10, 1 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment