Forum Academy Marketplace Showcase Pricing Features

How do I load plugin scripts in <body>?

I’m building a plugin which will include a JavaScript library and it needs to load in the <body>, for example:

<script src="http://example.com/script.js"></script>
<script>
    // code here...
</script>

In the plugin editor, I only see a way to load this in the <header> through Shared > HTML Header:

either in the header define <body></body> tags around it or do the same inside the div tags.

1 Like

At stated here, it’s not conventional to use multiple <body> tags.

…or do the same inside the div tags.

Could you elaborate on how to approach it this way?

just like the plugin builder is not conventional. I invite you to turn this code into a html file and open it in all of your browsers. you will find that even good old Microsoft Word displays the mark up correctly.

<html>
<head>
<body>
<h1>Hello World</h1>
</body>
  <title>Page Title</title>
</head>
<body>

<p>The content of the body element is displayed in the browser window.</p>
<p>The content of the title element is displayed in the browser tab, in favorites and in search engine results.</p>

</body>
</html>

For your case above in the header section, place

<body> 
<script src="http://example.com/script.js"></script>
</body>

inside the head section or depending on what your building maybe something like,

var div;
div = $('<div><body><script src="http://example.com/script.js"></script></body></div>');

apply logic to your plugin testing and most conventional methods will be soft guidelines.