Site logo

Archived topic

How to add javascript snippets to individual posts?

1 reply · Started by wordpressuser13 on February 8, 2023

Viewing posts 1–2 of 2

I am creating a website where for each post, I have to add a Javascript snippet inside the post, something like this:

<script src="CODE HERE

I tried adding it via the HTML block, and when I preview it in the backend the Javascript runs normally. However, when I view the post in the frontend, it doesnt'show anything.

I'm wondering if there's a way to add the Javascript code using hooks or generateblocks? Note that each post needs its own Javascript code. Maybe I can create a custom hook for each post? Is this possible?

Thank you so much for the help, really loving this theme and the support!

Hi there,

the HTML block should work, if not try adding a Classic Editor block, and set that to code view and add your script in there.

Otherwise you can use Hooks, but that would entail a new hook for each post ( set in the Display Rule > Location )... and that could result in a lot of admin work.

Let me know about the classic editor block.

This archived topic is closed to new replies.