Created
April 20, 2022 06:38
-
-
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/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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