WordPress.org

Ready to get started?Download WordPress

Forums

Exclude code from certain pages? (5 posts)

  1. byronb
    Member
    Posted 5 years ago #

    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

  2. adamrice
    Member
    Posted 5 years ago #

    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")

  3. byronb
    Member
    Posted 5 years ago #

    Thanks mate, I will try your suggestion.

  4. byronb
    Member
    Posted 5 years ago #

    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?

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    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 http://example.com/blog/page-slug.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.