01) Power of Javascript in WordPress Code

Learn how to link a Javascript file to the generated page at the right time according to its dependencies. There are two ways recommended for doing this, and we’ll examine them both plus explore the usefulness of Javascript in general.

JavaScript in Posts – Not all JavaScript may work; there could possibly be conflicts of one sort or another, such as with the automatic text formatting in the editor. There is a Text Control Plugin which allows you to control the automatic formatting features. If you choose No Formatting you will have to add paragraph tags and other HTML tags in order to format your page.

JavaScript in Template Files – The safe and recommended method of adding JavaScript to a WordPress generated page and WordPress Theme or Plugin is by using wp_enqueue_script(). This function includes the script if it hasn’t already been included, and safely handles dependencies.