Archived topic
Easiest way to add Javascript?
3 replies · Started by Daniel on July 21, 2020
I've been asked by a client to add a map which uses Javascript - what is the easiest way for me to add this to a page?
It looks like the below (with unique ID's removed).
`<div id = 'show-poi-widget-here'> </ div>
<script type = 'text / javascript'
src = ' https://api.easygis.eu/ js / latest.js '> </script>
<script type = 'text / javascript'>
easygis.loadModule ({
key: ' ',
module: easygis.Module.POIWIDGET,
target: 'show-poi-widget-here',
uuid: ''
});
</script>`
Hi there,
you could just add the HTML and JS straight into a HTML Block. As long as the Script comes after the HTML it will work.
Or you can use a Hook Element to add the <script> to the WP_footer
https://docs.generatepress.com/article/hooks-element-overview/
Then add the <div> within your content or another Hook.
Thanks David - I tried adding it as a custom HTML block previously but for whatever reason it didn't work and assumed I was doing something wrong.
This time... it did. So, case closed, thank you.
Glad to hear that :)