Forums

[resolved] Script For One Page (6 posts)

  1. cableghost
    Member
    Posted 2 years ago #

    With help from other members, I have discovered I need the below php code in my header which will run my script only on my home page.

    However, how do I set it to run only on another, specific page? Do I put the slug of the page in place of 'home' in the below script?

    <?php if(is_home()) { ?>CODE HERE..<?php } ?>

    -Scott

  2. hedonplay
    Member
    Posted 2 years ago #

    hello cableghost,
    to achieve this, you have to an 'or' condition inside 'if'

    thing goes as follows:

    <?php if(is_home()||is_page(array("please put your pages id here separated by comma"))) {} ?>

    don't hesitate to contact me if it doesn't work.

  3. cableghost
    Member
    Posted 2 years ago #

    Thanks Hedonplay. But won't adding this statement still leave the home page open to running the script?

    Let's say Page ID 324 is the only page I want the script to run on...would your code, entered as below, work for me?

    <?php if(is_home()||is_page(array("324"))) { ?>MY_SCRIPT_HERE<?php } ?>

    -Scott

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

    If you only want your script to work on page #324, then use:

    <?php if(is_page('324')) { ?>MY_SCRIPT_HERE<?php } ?>

  5. hedonplay
    Member
    Posted 2 years ago #

    Esmi is right, what I have shown is to run the scripts on both the home and others given pages.

  6. cableghost
    Member
    Posted 2 years ago #

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags