Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Putting Javascript in a Wordpress file (not a post) in the Body (not the head)

Posted on 2009-04-04
6
468 Views
Last Modified: 2012-06-27
I need to put javascript in the body of a Wordpress page.  It's not a blog or a post, but a  page.

As you know, apparently by default, Wordpress adds // to the javascript which prevents it from working (apparently for security reasons.)

It's for a "Thank you" page that needs the javascript in the body, and not int he head of the page.

Any suggestions?

Thanks

Rowby

 
<script id="pap_x2s6df8d" src="http://www.blahblah.net/affiliate/scripts/salejs.php" type="text/javascript">
</script>
<script type="text/javascript">
var sale = PostAffTracker.createSale();
sale.setTotalCost('1.0');
sale.setOrderID('ORD_12345XYZ');
sale.setProductID('test product');
PostAffTracker.register();
</script>

Open in new window

0
Comment
Question by:Rowby Goren
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:dosth
ID: 24067897
let me clear my self, so you created a thank you page and their you need to put the javascript, if so what is they issue you are facing. you can directly add this script.

can you tell me the issue?

thanks
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 24072472
Hi dosth

The problem is, when you paste javascript into the - body - of a file Wordpress automatically adds "\\" to the code apparently for security reasons.  This breaks the javascript code -- as you can see in my below snippet.
Below is what I pasted into the source code of my wordpress thank you page CODE tab:
 
<script src="http://www.blahblah.net/affiliate/scripts/salejs.php" id="pap_x2s6df8d" type="text/javascript"> </script>
<script type="text/javascript"> var sale = PostAffTracker.createSale(); sale.setTotalCost('1.0'); sale.setOrderID('ORD_12345XYZ'); sale.setProductID('test product'); PostAffTracker.register(); </script>
 
As soon as I saved it you will see below that Wordpress automatically added escapes "\" throughout the javasctipt.  This breaks the javascript.  And if I save it again it adds another \ to the javascript."  :(
 
 
<script src="http://www.blahblah.net/affiliate/scripts/salejs.php" id="pap_x2s6df8d" type="text/javascript"> </script><br />
<script type="text/javascript"> var sale = PostAffTracker.createSale(); sale.setTotalCost(\'1.0\'); sale.setOrderID(\'ORD_12345XYZ\'); sale.setProductID(\'test product\'); PostAffTracker.register(); </script>

Open in new window

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 24074021
Hello

Any other experts with a solution to this Javascript issue?

Thanks

Rowby
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 15

Accepted Solution

by:
dosth earned 500 total points
ID: 24074274
it will add when you do this via the wp-admin, if the thankyou page is your custom page, you can add it via any FTP tool. otherwise do this.

1. copy the js code to a include file
2. copy the inculde file to you thank you page.

you can see steps here

http://www.webreference.com/programming/javascript/external/
0
 
LVL 9

Author Closing Comment

by:Rowby Goren
ID: 31566567
Thanks for the solution and the links!  ...Rowby
0
 
LVL 15

Expert Comment

by:dosth
ID: 24122627
thanks for the points
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Like there are many different versions of Wordpress, there are also a handful of related side projects WordPress users should be familiar with.   All of these projects are open source and GPL licensed, which means there are few restrictions to us…
WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question