Solved

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

Posted on 2009-04-04
6
465 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
Comment Utility
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
Comment Utility
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
Comment Utility
Hello

Any other experts with a solution to this Javascript issue?

Thanks

Rowby
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 15

Accepted Solution

by:
dosth earned 500 total points
Comment Utility
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
Comment Utility
Thanks for the solution and the links!  ...Rowby
0
 
LVL 15

Expert Comment

by:dosth
Comment Utility
thanks for the points
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Who says nothing in life is free? WordPress.com is a freebie. WordPress.org's downloadable publishing platform is free. Heck, even WordPressMU is free. WordPress is an open source project, which means it can be used on any personal or commerc…
WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now