Hi,
I added the below code (skyscanner widget) in my post. But the widget doesn’t appear. Can you please give me the solution?
<script type=”text/javascript”>
skyscanner.load(“snippets”,”2″);
function main(){
var snippet = new skyscanner.snippets.SearchPanelControl();
snippet.setShape(“box400x400”);
snippet.setCulture(“en-GB”);
snippet.setCurrency(“USD”);
snippet.setProduct(“flights”,”1″);
snippet.setProduct(“hotels”,”2″);
snippet.setProduct(“carhire”,”3″);
snippet.draw(document.getElementById(“snippet_searchpanel”));
}
skyscanner.setOnLoadCallback(main);
</script>
<div id=”snippet_searchpanel” style=”width: auto; height:auto;”></div>
Hello Gaurav,
Unfortunately, we have no idea about the code provided by you and also, we do not know if it will work or not with our theme, sorry! Notice that the JS code should have been added in Custom Javascript Section, like this http://screencast.com/t/bW8Xf5H9HC or using a RAW JS on pages with Visual Composer. If it will not work you should contact the code provider because we are not aware to provide a solution in this regard and also, we cannot provide custom work at the moment, sorry!
Thanks for your understanding!
Hi,
Thanks for your reply. Above code works perfectly fine when I use raw js in visual composer on a page.
But when I copy and paste the code in text mode (not visual) in a post (not page), it doesn’t work.
So there is no problem with code as it works fine on a page.
Gaurav
Hello,
Well a post does not render the JS as the raw js element on a page. Please use this guide:
https://codex.wordpress.org/Using_Javascript
Thank you!
Dear Bogdan,
I have gone through that guide. But as I said the code works perfectly fine with visual composer’s raw js element.
It doesn’t work in posts. Can you try the code and tell me if something is wrong with the theme that doesn’t recognise the code in posts?
Best,
Gaurav
Dear Gaurav,
As you can tell from this guide, https://codex.wordpress.org/Using_Javascript the theme has nothing to do with the js rendering on posts. WordPress cannot render any javascript code inside a post without proper implementation. Please read the codex and use the correct method to implement a js code on a post.
http://screencast.com/t/IiI9BEnbKD7
Your code will not work only by pasting it inside a post.
A post is totally different from a raw js element on pages.
Maybe this will help:
https://www.godaddy.com/garage/webpro/wordpress/3-ways-to-insert-javascript-into-wordpress-pages-or-posts/
Thank you!
Dear Bogdan,
I fully understand that you do not provide custom work at present. But as a person who doesn’t know coding, I don’t understand the coding terminologies at all.
When it is written that .js script has to be created separately and it should be called in the post, where exactly should I create the script?
Actually it would be great and really helpful if you can explain with a practical small example, best help would be to do it with my code. But if its not possible then also it would be helpful with a sample code.
Best,
Gaurav
Hello,
The simplest way to do it if you are not familiar with coding is to use a plugin to insert js into a post. Tutorial from my previous reply shows how you can do this.
Sorry but your code does not do anything on my end even in a raw js element so I cannot test how it should or should not work. Please ask the person who provided the code for specific instructions to how it should be implemented and used as I cannot say for sure.
Thank you!
Dear Bogdan,
I tried the plugin as well. It didn’t help.
Although I tried the below code in raw js element of visual composer on a page and now it works perfectly fine.
If you can guide me how can I run the same code on a post by screenshot, it would be a great help really.
<script type=”text/javascript” src=”//api.skyscanner.net/api.ashx?key=ae5d22b7-42f9-475e-a227-5a8c56fbb1e7″></script>
<script type=”text/javascript”>
skyscanner.load(“snippets”,”2″);
function main(){
var snippet = new skyscanner.snippets.SearchPanelControl();
snippet.setShape(“box300x250”);
snippet.setCulture(“en-GB”);
snippet.setCurrency(“INR”);
snippet.setProduct(“flights”,”1″);
snippet.setProduct(“hotels”,”2″);
snippet.setProduct(“carhire”,”3″);
snippet.draw(document.getElementById(“snippet_searchpanel”));
}
skyscanner.setOnLoadCallback(main);
</script>
<div id=”snippet_searchpanel” style=”width: auto; height:auto;”></div>
Hi,
Try to add your code ins a Raw JS element and then switch to the classic mode and copy the shortcode then place it into your post content in Html Editor – http://screencast.com/t/vgUJotL2Mrp – http://screencast.com/t/IbjWFcrDRX9
Usually the js codes are implemented in the head section or footer and the div container is placed in the content where you would like the widget to appear.
Thanks!
-
This reply was modified 9 years by
Alin [tagDiv].