Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Created April 20, 2022 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webtoffee-git/442b23f89fdf506f27b8d8123e3ea32d to your computer and use it in GitHub Desktop.
Save webtoffee-git/442b23f89fdf506f27b8d8123e3ea32d to your computer and use it in GitHub Desktop.
To add “href” attribute to ‘a’ tags - CookieYes GDPR Cookie Consent (https://wordpress.org/plugins/cookie-law-info/)
<?php // do not copy this line
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>
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>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment