Add javascript to header of a specific page in gutenbeg

Hello,

I want to add javascript to head section of a specific post I have made in Gutenberg. I can add that code to an html block in gutenberg but I don’t know whether that would be equivalent in to adding in the head section (which is what I understand is recommended).

I know I can add the code in the pro theme post edit section, but the whole gutenberg post will disappear.

Do you know of any workaround for that?

Thanks.

Hello @ayham,

Thanks for writing in!

You can use Insert Headers and Footers plugin to add scripts. Please take a look at following resources to learn more:

Thanks.

Thanks!

Just a note. The plugin would insert that code into all pages. If I want to install the code in a specific post where can I find resources to learn how to do that?

thx.

Hey @ayham,

A quicker way would be to use the wp_head filter to insert that code in the header area of the site and use an if statement based on the page ID to specifically choose a page where the code should appear.

Please follow the suggestion here:

Hope this helps.

Thank you !

You are most welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.