-
AuthorPosts
-
January 17, 2017 at 1:58 pm #734702
Hello!
I need to install that script (http://ciaranmahoney.me/hide-full-phone-number-and-reveal-on-click-with-jquery/6689) to tracking click on phone number.
//////////////HTML/////////
<span id=”clickToShow”>123-456-7890</span>
////////////JavaScript//////////
var shortNumber = $(“#clickToShow”).text().substring(0, $(“#clickToShow”).text().length – 8);
var eventTracking = “_gaq.push([‘_trackEvent’, ‘EVENT-CATEGORY’, ‘EVENT-ACTION’, ‘EVENT-LABEL’]);”;
$(“#clickToShow”).hide().after(‘<button id=”clickToShowButton” onClick=”‘ + eventTracking + ‘”>’ + shortNumber + ‘… (click to show number)</button>’);
$(“#clickToShowButton”).click(function() {
$(“#clickToShow”).show();
$(“#clickToShowButton”).hide();
});January 18, 2017 at 5:51 am #735111Hey Bearded,
Try this in your functions.php file:
function bearded_add_custom_code(){ ?> <script> var shortNumber = $(“#clickToShow”).text().substring(0, $(“#clickToShow”).text().length – 8); var eventTracking = “_gaq.push([‘_trackEvent’, ‘EVENT-CATEGORY’, ‘EVENT-ACTION’, ‘EVENT-LABEL’]);”; $(“#clickToShow”).hide().after(‘<button id=”clickToShowButton” onClick=”‘ + eventTracking + ‘”>’ + shortNumber + ‘… (click to show number)</button>’); $(“#clickToShowButton”).click(function() { $(“#clickToShow”).show(); $(“#clickToShowButton”).hide(); }); </script> <?php } add_action('wp_footer', 'bearded_add_custom_code');
Best regards,
RikardJanuary 18, 2017 at 9:13 am #735195Does not work. The phone does not hidden and displays as plain text.
January 18, 2017 at 9:13 am #735196I use child theme.
- This reply was modified 7 years, 10 months ago by Bearded.
January 19, 2017 at 4:56 am #735662Hi,
Ok, thanks for the feedback. Could you link to the page where you are trying this please? The link you initially posted is returning a CDN error. Also please note that our support for third party code/plugins is limited.
Best regards,
RikardJanuary 19, 2017 at 12:06 pm #735813I understood. Link in “Private Content”.
January 23, 2017 at 7:36 am #737141Hi,
Please replace the code in the functions.php file with the following.
function ava_custom_script() { ?> <script type="text/javascript"> (function($) { var number = $("#clickToShow").text(); var length = number.length - 8; var shortNumber = number.substring(0, length); var eventTracking = "_gaq.push(['_trackEvent', 'EVENT-CATEGORY', 'EVENT-ACTION', 'EVENT-LABEL']);"; $("#clickToShow").hide().after('<button id="clickToShowButton" onClick="' + eventTracking + '">' + shortNumber + '… (click to show number)</button>'); $("#clickToShowButton").click(function() { $("#clickToShow").show(); $("#clickToShowButton").hide(); }); })(jQuery); </script> <?php } add_action('wp_footer', 'ava_custom_script');
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.