Adding JavaScript Using the Custom HTML Block

You can add JavaScript to your WordPress content using a Custom HTML block.

For example, the following will output some text:

<script>
let message = '<p style="color:red">Hi from a Custom HTML Block!</p>';
document.write(message);
</script>

Just like this:

Ensure you include the opening <script> and closing </script> tags.

You can also add JavaScript (and CSS) to every page of your site using a plugin.


Parent page: