Support » Fixing WordPress » Is it possible to add a code only to ONE page?

  • Hello,

    I want to add a code (its a live sales chat code) to my wordpress site.

    But I just want that to appear only on ONE page which is the sales page.

    Is that possible?

    They asking to place the code above </body> tag. So is there any way to place on individual page.


Viewing 12 replies - 1 through 12 (of 12 total)
  • @maheshone

    The following script should do what your after, in the below example it will allow you to add some code to just the homepage, a simple modification will allow you to specify a page ID.

    <?php if(is_front_page() ) { ?>
    <?php } else { ?>
    <?php } ?>

    Hope this helps,

    Can you give me a source to read more about it? I still have no clue about how to do it..


    Here’s a bit more on the uses of if else statements, after the if you’d put what it was you wanted to execute, so in your case it would be the chat code, then after the else tag you’d run any code you wanted on pages which weren’t needed on the homepage.


    The code looks like this…

    `<!– begin olark code –><script type=’text/javascript’>/*{literal}<![CDATA[*/
    window.olark||(function(c){var f=window,d=document,l=f.location.protocol==”https:”?”https:”:”http:”,z=
    /* custom configuration goes here ( */
    <!– end olark code –>

    why should I use the if.. else?

    I must use the IF naaa?

    that is…

    If Page ID=X

    Then execute this code…

    Why should I use else part?

    And where should I use this code? On header.php?


    Sure you can just use if, I was just trying to explain that you can use it do some tricky things with the else depending on the requirements of your theme. Anyhow there are many guides online if you need further assistance.

    The code itself can be placed pretty much anywhere so if you need it within the header.php file it should work perfectly.


    Alright… I will give a try… never played with PHP much.. other than just simple editing…

    Guys… it was so easy.. I have done that… I created a Page Template and added the Olark code to that template’s footer… and its working… although Olark says to place the code above </body> which is in footer.php I placed the code at the end of the new page template. Will soon paste the URLs to show…

    Typically, in WP themes anyway, ‘footer’ is part of <body>…review your site’s source code to see this in action. Find the starting body tag <body> and the closing one </body>

    Okay. I see that the code was placed below “</body>
    </html>” but the chat function was still working.. then I placed the code above <?php get_footer(); ?>

    Now, the code is showing above </body> but NOT IMMEDIATELY above </body>. Still the chat function is working… and i think it affected a site speed a little bit not sure.. checking.. i changed the template of an private page… to the new one…

    If you want the code in the footer, use a child theme and add it to footer.php.

    am new to child theme… will it affect page speed? so i need to create another directoroy called new theme and then upload the files styles.css and the same page.php and NEW footer.php right?

    Basically, yes, create a test site or sub-domain – Please see Child Themes on the codex.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Is it possible to add a code only to ONE page?’ is closed to new replies.