Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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();
    });

    #735111

    Hey 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,
    Rikard

    #735195

    Does not work. The phone does not hidden and displays as plain text.

    #735196

    I use child theme.

    • This reply was modified 7 years, 11 months ago by Bearded.
    #735662

    Hi,

    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,
    Rikard

    #735813

    I understood. Link in “Private Content”.

    #737141

    Hi,

    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

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.