How to Easily Add JavaScript in WordPress Pages or Posts (3 Methods)


3 ways to insert JavaScript into WordPress pages or posts
Ollie Reyes

If you are unsure about the health of your JavaScript code, just use the Fetch as Google option. The Fetch as Google tool lets you test how Google crawls or renders a WordPress page or post. You can use this tool to see if the Googlebot can access a page on your site, view how it renders the page, and determine if any page resources are being blocked to the Googlebot. This tool simulates Google’s crawl and render process, so it is the perfect tool for debugging and discovering possible JavaScript issues within your website.

How to Add Javascript in a WordPress Post or Page
Mindy Russell

That’s great but as the custom_function() will be added to the footer it will be available to to every post or page. This might be a good thing but could impact on the performance if not all the pages require it. Lets say you need a JavaScript framework for a single post that you created. This might not be required for every page and it would waste a HTTP request.

WordPress.org
Mary Hudson

If you are having trouble with including JavaScripts inside a post, use the Text Control Plugin which allows you to control on a global or per post basis the ability to turn off WordPress’s automatic formatting features which can quickly turn a code into something readable instead of executable. Set the options on the post that you will be using the JavaScript on to have No Formatting or Markup or nl2br and No Character Formatting. You may have to experiment to get it to work. As a reminder, when using the Text Control Plugin, you must first Save and Continue Editing the post in order to see the Text Control Plugin options.

3 ways to insert JavaScript into WordPress pages or posts
Tiffany Ballard

5. Now we need to add our Header Script and Footer Script custom fields and output them correctly. There are two key settings; the field name that will be referenced later in the template code and the formatting. You must set the formatting to the “Convert HTML into tags” option so that the contents that are pasted are properly executed in the template.

Be the first to comment

Leave a Reply

Your email address will not be published.


*