Add javascript to WordPress post

How to add javascript codes to a WordPress page or post ?

If you add your javascript code into your post or page directly. It won’t work. Nothing will happen as the code is considered like text with paragraphs. Check the source code of the page.

So, you need a plugin to convert your code into shortcode.

For example :

Code embed,
Custom fields shortcode.

Once the plugin installed, click on add new (to create a new post or page) and in screen options, check the “custom fields” box. At the bottom of the page, click on enter new in the custom fields tab, enter a name and copy paste your javascript into the value field.

Finally add %YOURCODE% in your post where you want to add the javascript. Where YOURCODE is the name of your javascript code.