Need help with sidebar.php -- displaying html script on specific page sidebar (2 posts)

  1. gwen0
    Posted 6 years ago #

    Hi everyone,

    When adding an html script to sidebar.php - the script displays on all pages. (I'm trying to have this html script display only on one page)

    So I decided to create a page template, and been trying to find a way where I can add this html script to display on my page template "sidebar".

    Not having the best luck. Can someone give me a hint as how to do this, or if there is any "exclude page" sidebar widget out there for text/script?

  2. xdesi
    Posted 6 years ago #

    Just add some conditionals inside a PHP if statement around the HTML you only want on one page. For example:

    <?php if(is_page('7'){ ?>
    <p>Hello I only appear on Page 7 </p>
    <?php } ?>

    This code will only appear on the page with an ID of 7, obviously you can change this number as you like, or even to a page-name.

Topic Closed

This topic has been closed to new replies.

About this Topic