Tagged: cornerstone
-
AuthorPosts
-
June 15, 2016 at 8:11 am #1043153
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!
June 15, 2016 at 10:19 am #1043402Hi 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.
June 15, 2016 at 11:04 am #1043486Thank 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!
June 15, 2016 at 11:38 am #1043532Never mind – the customer sent incomplete information, I’ve got this working now.
June 15, 2016 at 12:56 pm #1043657Happy to hear that. Feel free to ask us again. Have a great day! 🙂
-
AuthorPosts