Forums

Code to display an image on normal page and single page only (4 posts)

  1. danaldinho
    Member
    Posted 2 years ago #

    Does anyone know the code to make an image show on the single post and pages only?

    This code below works:

    <?php if (is_page()) : ?>
    IMAGE GOES HERE
    <?php endif; ?>
    <?php if (is_single()) : ?>
    IMAGE GOES HERE
    <?php endif; ?>

    But I was looking at only posting the image once in one piece of code. I have tried this:

    <?php if (is_single() && is_page()) : ?>
    IMAGE GOES HERE
    <?php endif; ?>

    But no luck :(

    Hope someone can help me out.

    Thanks, appreciate it.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Your current code translates to "If this is a single post AND a static page..." which, obviously is never going to be true. Try:

    <?php if (is_single() || is_page()) : ?>
    IMAGE GOES HERE
    <?php endif; ?>

    which replaces your AND with an OR.

  3. Lynne and Chad
    Member
    Posted 2 years ago #

    Is it the same image you want to use all the time? Or different for each post?

    If it's just one image to be used on all posts, you should be able to add the image tag to the single.php file in your theme and be all set :)

  4. danaldinho
    Member
    Posted 2 years ago #

    Thanks esmi, appreciate it.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.