Forums

How do I add a script for just one page (8 posts)

  1. cableghost
    Member
    Posted 2 years ago #

    My tracking software requires me to place a script in ONLY the home/index of my site, however, since WP is template based, the script will appear on every page; I am unsure how to accomplish this.

    -Scott

  2. esmi
    Theme Diva & Mod
    Posted 2 years ago #

    <?php if(is_home() [ do stuff] ;?>

  3. cableghost
    Member
    Posted 2 years ago #

    pardon my ignorance...do I place the script then inside the php call?

    Such as...<?php if(is_home() <script>do stuff</script> ;?>

    Or do I need an ending tag?

    -Scott

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    <?php if(is_home()) { ?>
    CODE HERE..
    <?php } ?>
  5. cableghost
    Member
    Posted 2 years ago #

    Thank you...Would I then place this in the first line of my main index or page template?

    -Scott

  6. Mark / t31os
    Moderator
    Posted 2 years ago #

    Wherever your script needs to go (putting the PHP aside for a moment)..

    Your script still goes where it needs to, most likely in between <head> and </head> if it's <script> kinda code.....

    No different to how you'd do it in a normal HTML page, the only difference here is it's wrapped in the necessary PHP to conditionalise when the code is printed into the page..

  7. cableghost
    Member
    Posted 2 years ago #

    Got it, thank you!

  8. cableghost
    Member
    Posted 2 years ago #

    Actually, what if I wanted the script to reference a page other than the site's Home page?

    I have a main site and another separate review site that I would like to combine. The review site, though it would become just a page on the main site, it will still have its own domain through redirection...how would I reference the script for only that page?

    -Scott

Topic Closed

This topic has been closed to new replies.

About this Topic