Solved

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

Posted on 2009-04-04
6
467 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

785 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