- Creating a Multiple Script File
- Method 1: Disable WordPress filtering of script tags
- Method 2: Use a plugin to enable script includes
- When the Script is in an External File
- Related Posts
- Reader Interactions
- Comments (22 responses)
Be sure that you define the type correctly, as your site will not validate without it.
Creating a Multiple Script File
If you choose No Formatting, your post’s text will all run together, so you will have to add paragraph tags and other HTML tags in order to format your page as WordPress normally does that for you.
If you are really having trouble with this, the WordPress Support Forum may be able to help.
Last updated on August 19th, 2022 by Editorial Staff | Reader Disclosure Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.
Usually, these scripts will go in the header or footer section of your WordPress blog, so the code is loaded on every page view.
For example, when you install Google Analytics, the code needs to run on every page of your website, so it can track your website visitors.
You can manually add the code to your header.php or footer.php files, but these changes will be overwritten when you update or change your theme.
WPCode is the most powerful code snippet plugin available for WordPress. It lets you easily add custom code to any area of your site, and best of all, it’s free.
First, you need to install and activate the free WPCode plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.
Once activated, you need to go to Code Snippets » Headers & Footer.
Here you will see three separate fields labeled ‘Header,’ ‘Body,’ and ‘Footer.’
You can also add code snippets to any other place on your site, such as inside posts or pages.
To do this, simply go to Code Snippets » + Add Snippet and then click on ‘Create Your Own.’
You will now see a ‘Create Custom Snippet’ page where you can add a title for your code and paste it into the ‘Code Preview’ box.
Then, just scroll until you find the ‘Insertion’ section.
All you have to do now is select a ‘Location’ for the code from the dropdown menu. Find ‘Page, Post, Custom Post Type’ and choose where in the page or post you want the code to appear.
If you choose to have WPCode insert the snippet before or after a paragraph, you will be able to choose which specific paragraph in the post it will appear before or after.
For example, if you put 1 in the ‘Insert Number’ field, the code snippet will appear before or after the first paragraph. Use 2 for the second paragraph, and so on.
After that, you just have to click the toggle near the top of the screen to switch to ‘Active,’ and then click ‘Save Snippet’ button beside it.
That’s all it takes to make your code snippet live on site!
With this method, you need to add code to your WordPress files. If you haven’t done this before, then check out our guide on how to copy and paste code in WordPress.
First, we’ll show you how to add code to your WordPress site’s header. You need to copy the following code and add it to your functions.php, in a site-specific plugin, or by using a code snippets plugin.
Take a look at the following code snippet:
Take a look at the following example:
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
The GoDaddy product information in this article is outdated and currently under review for accuracy. For the latest up-to-date product information please visit godaddy.com
The WordPress editor both autoformats your text and restricts the types of tags that are inserted into your content. While some users who are attempting to insert scripts find this frustrating, it’s not a design flaw. Blocking the ability to insert scripts is a security feature.
The purpose of a content management system (CMS) like WordPress is to separate content from design. Ensuring that the administrator sets formatting and layout options at the theme level prevents the WordPress site’s authors from modifying the design.
- Players — Some audio and video players require a script to display the player within the page.
- Interactive pages — Interactive pages and calculators require embedding of third-party scripts within a site.
- Third-party forms — Subscription and lead generation forms often have remotely loaded scripts that need to be included in the header, body or footer of the page.
- Disable WordPress filtering of script tags
- Using a plugin to enable script loading
- Using Advanced Custom Fields
Let’s get into the details.
Method 1: Disable WordPress filtering of script tags
Within your functions.php page, you can add the following code:
Note: Once again, we have to warn against using the above method. Enabling the script tag via this method disables the security feature sitewide for any user permission level.
Method 2: Use a plugin to enable script includes
Last updated: August 10, 2013
One of my readers asked me the following question:
When the Script is in an External File
After you have included the file you can use any functions that is defined in that file. Use something similar to the following:
Replace “custom_function();” with the actual name of the function.
Comments (22 responses)
Thank you very much . You really saved me.
Thanks for post but super confused. This post starts out by saying its as easy as entering text. That’s not working for me. Then the video lays out like four steps that are required.
I only want a price comparison tool to appear in a single post. Tried a JS plugin and that failed as well. Anyone feel like helping a newbie out? 😉
For site-wide alterations, I always prefer to use a plugin rather than a manual edit, but for a single time need, like when having a special piece of code to add to a specific post or page, then this would work like a treat.
Great tutorial, admin!