Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1043153

    savantmg
    Participant

    Hello,
    This user wants to add a booking button via the following script:

    <script>
    (function(idPrefix) {
    id = idPrefix+’-js’; if (document.getElementById(id)) return;
    var head = document.getElementsByTagName(‘head’)[0];
    el = document.createElement(‘script’); window.peekButton=’Book Now’; el.id = id;
    var date = new Date; var stamp = date.getMonth()+”-“+date.getDate();
    el.src = “https://pirassets.s3.amazonaws.com/assets/widget_button.js?id=57434fb706ecd769f0003baf&ts=”+stamp;
    head.appendChild(el); id = idPrefix+’-css’; el = document.createElement(‘link’); el.id = id;
    el.href = “https://pirassets.s3.amazonaws.com/assets/widget_button.css?id=57434fb706ecd769f0003baf&ts=”+stamp;
    el.rel=”stylesheet”; el.type=”text/css”; head.appendChild(el);
    }(‘peek-booking-button’));
    </script>

    As this places a booking button through their Peek Pro system, I don’t know how I can add this via the Custom JS to appear where it needs to be placed. Any advice, such as via functions.php in child theme? If I try adding it via Raw Content or Text the page will not save.

    Thanks!

    #1043402

    Jade
    Moderator

    Hi there,

    Please see this thread for the solution via functions.php https://community.theme.co/forums/topic/adding-external-javascript-to-a-single-page/#post-169864

    Hope this helps.

    #1043486

    savantmg
    Participant

    Thank you for the reply – it looks like that will load the JS, but the JS noted above needs to be in a specific location (it supposedly adds a booking button) so this needs to be called in a specified location.

    I found another thread that appears to be more suited to what we need: https://community.theme.co/forums/topic/inserting-javascript-into-raw-content-element-in-cornerstone/

    I have added to my functions.php file in the child theme:

    function load_script_content() {
    	return "<script type='text/javascript' src='http://www.stjohnislandtours.com/wp-includes/js/book-button.js'></script>";
    }
    
    add_shortcode('custom_script', 'load_script_content');
    

    And I have uploaded the JS file (and confirmed it is loading in Firebug), I then added a raw content with the [custom_script] tag and it doesn’t appear to be working.

    Is this solution still viable and if so, where have I gone wrong?

    Thanks!

    #1043532

    savantmg
    Participant

    Never mind – the customer sent incomplete information, I’ve got this working now.

    #1043657

    Prasant Rai
    Moderator

    Happy to hear that. Feel free to ask us again. Have a great day! 🙂