• Hello there, I have created an opt in form called optin.php. I want to display it only on my home page (static page). I created optin.php and include the code in my page.php (<?php include(TEMPLATEPATH . ‘/optin.php’); ?>). I only want it to appear on my homepage (a specific page set to my home page), how do I stop it from appearing on all my other pages?

    Regards,
    Byron

Viewing 4 replies - 1 through 4 (of 4 total)
  • There’s more than one way to do this. You could create a specific “home.php” template and only invoke that include on that file. Or you could use conditional tags with something like this:

    <?php
    if is_page('home') {
    include(TEMPLATEPATH . '/optin.php');
    }
    ?>

    (this assumes the page name is actually “home”)

    Thread Starter byronb

    (@byronb)

    Thanks mate, I will try your suggestion.

    Thread Starter byronb

    (@byronb)

    Sorry mate, I have tried different conditional statements but doesnt seem to work. You said “(this assumes the page name is actually “home”) “, how do I find out the name of the page?

    I added the opt in code to my page.php, is this correct?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Try if (is_page('home')) instead.

    And “home” is the Page’s slug. It’s the bit that’s part of the Page’s URL. Like https://example.com/blog/page-slug.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude code from certain pages?’ is closed to new replies.