Tagged: yigit
-
AuthorPosts
-
January 20, 2016 at 7:44 pm #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=’ + 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.
January 21, 2016 at 12:01 am #568984Hey 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,
YigitJanuary 21, 2016 at 12:12 am #568987Hi 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,
SusanneJanuary 22, 2016 at 10:06 am #569863Hi!
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,
VinayJanuary 22, 2016 at 11:38 am #569918Hi 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 33Now 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, 11 months ago by Susanne.
January 22, 2016 at 4:30 pm #570196Hey!
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,
YigitJanuary 22, 2016 at 6:02 pm #570255Hi 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,
SusanneJanuary 25, 2016 at 7:04 pm #571559could anybody help please?
January 27, 2016 at 6:05 am #572594Hey!
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_pageRegards,
IsmaelJanuary 27, 2016 at 11:13 am #572737Hi 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,
SusanneJanuary 27, 2016 at 11:37 am #572756Hey!
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!
AndyJanuary 27, 2016 at 12:33 pm #572793Hi 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=’ + 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!
January 27, 2016 at 12:45 pm #572801Hi!
is this site a WordPress site?? if yes which theme are you using? can you provide us admin access for this one please?
Regards,
AndyJanuary 27, 2016 at 12:54 pm #572807No Andy, this is a .html website.
January 27, 2016 at 1:29 pm #572842Hey!
make sure that you script is compatible with WordPress. Otherwise we can’t help you much.
Regards,
Andy -
AuthorPosts
- You must be logged in to reply to this topic.