Solved

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

Posted on 2009-04-04
6
466 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 Horizontal Drop-Down Menu In this tutorial I will show you had to add a WordPress horizontal navigation menu to your theme. I have searched and searched for a good tutorial on creating a WordPress nav menu without adding a plug-in or us…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. 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 : Open Page or Post…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now