Correct code snippet – inside functions.php file is:
add_action('wp_head', 'wt_cli_add_href_to_links', 1);
function wt_cli_add_href_to_links() {
if (!class_exists('Cookie_Law_Info')) return;
$script = '<script>
window.addEventListener( "DOMContentLoaded", addHrefToLinks );
function addHrefToLinks() {
var wt_cli_links = document.querySelectorAll( "#cookie-law-info-bar a, #cliSettingsPopup a" );
wt_cli_links.forEach( el => {
if(!el.hasAttribute("href"))
el.href = "#";
});
}';
$script .= '</script>';
echo $script;
}