WordPress.org

Ready to get started?Download WordPress

Forums

PHP is_single in post? (6 posts)

  1. teccus
    Member
    Posted 7 years ago #

    Is there anyway I can use code like this is my post?

    <?php
    if (is_single()) {
    echo '<img src=\"test.jpg\" alt=\"Test Image\" />';
    }
    ?>

    Because at the moment it's not allowing me too.

  2. whooami
    Member
    Posted 7 years ago #

    you want the code to execute or just be displayed? your question isnt clear?

    You cannot simply paste php, (or any language for that matter) into a post, especially if you want it to be executed.

  3. teccus
    Member
    Posted 7 years ago #

    Well I want that image from that post to be displayed only if it is on the single.php...

    So eg..

    Text text text

    <display pic if is single.php

    Text text text

    Why can't I use php in my post?

  4. whooami
    Member
    Posted 7 years ago #

    Why can't I use php in my post?

    Because its not "safe" for starters. Because the wp devs care. Doesnt really matter.

    The solution is easily found though via that magical search function:

    http://wordpress.org/search/php+inside+a+post?forums=1

  5. teccus
    Member
    Posted 7 years ago #

    Yes the search function is magical. But none of those posts solve my problem. The plugins only allow 'Echo'..

    They don't allow me to do if(is_single()), do they..

  6. whooami
    Member
    Posted 7 years ago #

    I reckon if you cannot find a plugin that works than youre left to code your own plugin, ask someone else to write you a plugin, or find another way to accomplish whatever it is you're trying to do.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags