thankyou.php script
-
Hi,
Can someone tell me please how to load a javascript between <head> and </head> only on thankyou.php page? I don’t want this script to be loaded on whole website only on this page.
Thanks
-
The <head> tags typically should only be in header.php.
Yes. but I need to add a script in thankyou.php head. But I don’t have head in thankyou.
The way WordPress functions is that there is a header.php to load the header for all pages. This makes it easier to edit the header since it is in one place. Thus, you can add the script to the header.php, but use conditionals to see if it is the thankyou page and if it is then load the script.
Perhaps it would also help if you reviewed the template hierarchy in Theme Development?
respectyoda can you show me a example please?
I think will be something linke this
if page is (thankyou.php)
my scriptif( is_page( 'order-received' ) ) { // statements }
Means do < statements > when the page with the slug of “order-received” is being displayed.
If I try to add your code or this kind of cod in head.php :
<?php
if ( is_page(‘about’) || is_page(‘contact’)) {
echo ‘<div id=”secondnav”>This is the super cool secondary navigation.</div>’;
}
?>The website will stop working and I get only a blank white page.
Ensure there is only one “<?php” on the first line of the file, and no “?>”s.
Sorry I can’t understand what you try to tell me.
This is my javascript i need to be implemented in thankyou.php page but this page don’t have <head>.The only file where I found is on header.php.
1.Copy and paste the following code between <head> and </head> on the page of your website on which you want to track actions. For example, to track registrations, place the code on your ‘registration completed’ web page.
<script type=”text/javascript”>
var fb_param = {};
fb_param.pixel_id = ‘XXXXXXXXXX’;fb_param.value = ‘0.00’;
fb_param.currency = ‘USD’;
(function(){
var fpw = document.createElement(‘script’);
fpw.async = true;
fpw.src = ‘//connect.facebook.net/en_US/fp.js’;
var ref = document.getElementsByTagName(‘script’)[0];
ref.parentNode.insertBefore(fpw, ref);
})();
</script>
<noscript><img height=”1″ width=”1″ alt=”” style=”display:none” src=”https://www.facebook.com/offsite_event.php?id=6016044956826&value=0¤cy=USD” /></noscript>You have to either use the slug or the ID of the thankyou.php page in the conditional. So go to header.php and locate the <head> tags. Within the <head> tags, do this.
<?php if ( is_page('slug') ){ ?> //put the script code here <?php } ?>
Once again, either use the slug or the ID of the page.
Hi, The full javascript comes later. The first task is to get something working on the thank you page only. So put this in header.php :
if( is_page( 'order-received' ) ) { echo '<script type="text/javascript">alert("Hello");</script>'; }
Do not use <?php because there will be one of these tags already at the top of the page.
Do not use ?>
You should get an alert box on the thank you page only. Does this work for you?
Iorro,
<?php
may need to be used if it is closed by a?>
before the <head> tags. At this juncture, we don’t know if this is the case or not.My ID for order complete page is 9.
<?php if ( is_page(‘9’) ){ ?>
//put the script code here
<?php } ?>If one is using an ID then don’t use quote marks. Quote marks are only to be used with a slug. I should have mentioned that earlier.
So…
<?php if ( is_page(9) ){ ?> <script type="text/javascript"> var fb_param = {}; fb_param.pixel_id = 'XXXXXXXXXX'; fb_param.value = '0.00'; fb_param.currency = 'USD'; (function(){ var fpw = document.createElement('script'); fpw.async = true; fpw.src = '//connect.facebook.net/en_US/fp.js'; var ref = document.getElementsByTagName('script')[0]; ref.parentNode.insertBefore(fpw, ref); })(); </script> <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/offsite_event.php?id=6016044956826&value=0¤cy=USD" /></noscript> <?php } ?>
respectyoda thanks very much.Now is working good.I hope facebook will activate now statistics for website.Again thanks very much.
- The topic ‘thankyou.php script’ is closed to new replies.