Tagged: 

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #568842

    URL: http://www.templates.4ucreated.co.uk/

    Hi there,
    I’m trying to add a script (availability checker of Booking.com) to the testing site of our new B&B website. (code see below)
    Enfold doesn’t accept it – what shall I do?

    <script>
    (function() {
    var randomId = Math.floor(Math.random() * 100000);
    var targetElemId = ‘bcom_rwidget_’ + randomId;
    document.write(‘
    <div id=”‘ + targetElemId + ‘”></div>
    ‘);
    var script = document.createElement(‘script’);
    script.type = ‘text/javascript’;
    script.async = true;
    script.src = ‘http://www.booking.com/review_widget/gb/the-manor-house-bed-amp-breakfast-trunch.en.html?tmpl=review_widget/review_widget&wid=&#8217; + targetElemId + ‘&wtype=box_small&hotel_id=1283558&widget_language=en’;
    var node = document.getElementsByTagName(‘script’)[0];
    node.parentNode.insertBefore(script, node);
    }());
    </script>

    Thanks for your support.

    #568984

    Hey Susanne!

    Please add following code to Functions.php file in Appearance > Editor

    function add_custom_code(){
    ?>
    YOUR CODE GOES HERE
    <?php
    }
    add_action('wp_footer', 'add_custom_code');

    Regards,
    Yigit

    #568987

    Hi Yigit,
    Thank you for this.
    I added your code to functions.php.
    I’m a bit confused: Should I insert the script code instead of “YOUR CODE GOES HERE”?
    Anyway – I also inserted the script code into functions.php, and then I tried again to insert the script on the home page (http://www.templates.4ucreated.co.uk/) where the availchecker box should show.

    But again – the advanced editor won’t save it once I add the script.
    Please can you have a look? You’ve got the login credentials?

    Thanks,
    Susanne

    #569863

    Hi!

    That is correct you need to add from <script> to </script> where it say’s your code goes here and then goto appearance > editor > functions.php and paste it at the bottom.

    Please check the code below everything should go in functions.php if you still have issue please get back to us with admin login info as private content so we can take a look at it.

    
    
    //your comments for the code block below
    function add_custom_code(){
    ?>
    <script>
    (function() {
    var randomId = Math.floor(Math.random() * 100000);
    var targetElemId = ‘bcom_rwidget_’ + randomId;
    document.write(‘
    <div id=”‘ + targetElemId + ‘”></div>
    ‘);
    var script = document.createElement(‘script’);
    script.type = ‘text/javascript’;
    script.async = true;
    script.src = ‘http://www.booking.com/review_widget/gb/the-manor-house-bed-amp-breakfast-trunch.en.html?tmpl=review_widget/review_widget&wid=’ + targetElemId + ‘&wtype=box_small&hotel_id=1283558&widget_language=en’;
    var node = document.getElementsByTagName(‘script’)[0];
    node.parentNode.insertBefore(script, node);
    }());
    </script>
    <?php
    }
    add_action('wp_footer', 'add_custom_code');
    

    Best regards,
    Vinay

    #569918

    Hi Vinay,
    I added the code to functions.php. Now I get this error message:
    Fatal error: Cannot redeclare add_custom_code() (previously declared in /home/ucreated/public_html/templates/wp-content/themes/enfold-child/functions.php:12) in /home/ucreated/public_html/templates/wp-content/themes/enfold-child/functions.php on line 33

    Now I cannot open the theme editor at all. Although I re-uploaded the original functions.php and functions-enfold.php,
    I still cannot access the editor at all, only get the error message.
    The whole website doesn’t open anymore. Although I deleted all 3 functions.php files on the server, then re-uploaded them.
    Please help.
    Thanks,
    Susanne

    • This reply was modified 8 years, 10 months ago by Susanne.
    #570196

    Hey!

    It seems like you already had a function named “add_custom_code”. Overwriting the file or removing the code via FTP should have helped. If you are still having the issue, please post FTP and WP admin credentials here privately.

    Regards,
    Yigit

    #570255

    Hi Yigit & Vinay,
    I managed to delete the code from enfold-child/functions.php. Now it is only on functions.php, and the website is back online.

    However, I need to run this script based widget on the homepage. When I insert the script code into a text element on the homepage in Advanced Editor, I cannot save the element which contains the script. The editor just won’t accept the script.

    How do I integrate the script on the page & exact place where I want it to be shown?
    Thanks for your support,
    Susanne

    #571559

    could anybody help please?

    #572594

    Hey!

    Use conditionals such as is_home, is_front_page or is_page:

    //your comments for the code block below
    function add_custom_code(){
    if(is_front_page()) {
    ?>
    <script>
    (function() {
    var randomId = Math.floor(Math.random() * 100000);
    var targetElemId = ‘bcom_rwidget_’ + randomId;
    document.write(‘
    <div id=”‘ + targetElemId + ‘”></div>
    ‘);
    var script = document.createElement(‘script’);
    script.type = ‘text/javascript’;
    script.async = true;
    script.src = ‘http://www.booking.com/review_widget/gb/the-manor-house-bed-amp-breakfast-trunch.en.html?tmpl=review_widget/review_widget&wid=’ + targetElemId + ‘&wtype=box_small&hotel_id=1283558&widget_language=en’;
    var node = document.getElementsByTagName(‘script’)[0];
    node.parentNode.insertBefore(script, node);
    }());
    </script>
    <?php
    }
    }
    add_action('wp_footer', 'add_custom_code');

    https://developer.wordpress.org/reference/functions/is_page/
    https://codex.wordpress.org/Function_Reference/is_front_page

    Regards,
    Ismael

    #572737

    Hi Ismael,
    Now I get the following error message:
    Parse error: syntax error, unexpected $end in /home/ucreated/public_html/templates/wp-content/themes/enfold-child/functions.php on line 30
    Again, the website doesn’t show any more, even after deleting the code.

    Please help,
    Susanne

    #572756

    Hey!

    are you sure your script is correct? where did you get it from? does it work for you when activating a default WordPress theme instead?

    Cheers!
    Andy

    #572793

    Hi Andy,
    I added the 2 scripts I need to be inserted to an .html page, and both widgets show without any problem, see here:
    http://www.manorhousetrunch.co.uk/test.html
    (The bottom widget (booking.com) is the one I gave you the script code for, but indeed I need both on enfold).
    So the script is correct.

    Again, this is the script:
    <script>
    (function() {
    var randomId = Math.floor(Math.random() * 100000);
    var targetElemId = ‘bcom_rwidget_’ + randomId;
    document.write(‘<div id=”‘ + targetElemId + ‘”></div>’);
    var script = document.createElement(‘script’);
    script.type = ‘text/javascript’;
    script.async = true;
    script.src = ‘http://www.booking.com/review_widget/gb/the-manor-house-bed-amp-breakfast-trunch.en.html?tmpl=review_widget/review_widget&wid=&#8217; + targetElemId + ‘&wtype=button_dark_ver&hotel_id=1283558&widget_language=en’;
    var node = document.getElementsByTagName(‘script’)[0];
    node.parentNode.insertBefore(script, node);
    }());
    </script>

    Thanks for your support and patience!

    #572801

    Hi!

    is this site a WordPress site?? if yes which theme are you using? can you provide us admin access for this one please?

    Regards,
    Andy

    #572807

    No Andy, this is a .html website.

    #572842

    Hey!

    make sure that you script is compatible with WordPress. Otherwise we can’t help you much.

    Regards,
    Andy

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