WordPress.org

Ready to get started?Download WordPress

Forums

Is it possible to add a code only to ONE page? (13 posts)

  1. Mahesh Mohan
    Member
    Posted 2 years ago #

    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.

    Thanks!

  2. James Duffell
    Member
    Posted 2 years ago #

    @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,
    ^JD

  3. Mahesh Mohan
    Member
    Posted 2 years ago #

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

  4. James Duffell
    Member
    Posted 2 years ago #

    @maheshone

    Here's a bit more on the uses of if else statements http://www.w3schools.com/php/php_if_else.asp, 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.

    ^JD

  5. Mahesh Mohan
    Member
    Posted 2 years ago #

    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 (www.olark.com/documentation) */
    olark.identify('3064-175-10-3163');/*]]>{/literal}*/</script>
    <!-- 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?

  6. James Duffell
    Member
    Posted 2 years ago #

    @maheshone

    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.

    ^JD

  7. Mahesh Mohan
    Member
    Posted 2 years ago #

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

  8. Mahesh Mohan
    Member
    Posted 2 years ago #

    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...

  9. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

    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>

  10. Mahesh Mohan
    Member
    Posted 2 years ago #

    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...

  11. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

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

  12. Mahesh Mohan
    Member
    Posted 2 years ago #

    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?

  13. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic