Support » Plugin: Insert PHP » Manually specified HTML between PHP

  • Resolved estr

    (@estr)


    Hello,

    I have the following code:

    ————-
    <?php if (is_single()) { ?>

    <p>Some text.</p>

    <?php } ?>
    ————-

    I have tried to put the following in a post:

    ————-
    [insert_php] if (is_single()) { [/insert_php]

    <p>Some text.</p>

    [insert_php] } [/insert_php]
    ————-

    But it does not work the way that it should. “Some text.” is displayed on both in the post, as well as on the front page, which should not be the case.

    Could you please assist with this?

    Thank you!

    http://wordpress.org/plugins/insert-php/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WillBontrager

    (@willbontrager)

    estr, each [insert_php]…[/insert_php] block of code needs to be complete. Complete being that it will run independently.

    [insert_php]if(is_single()){[/insert_php]

    won’t run by itself.

    Insert PHP works by putting the code found between the [insert_php] [/insert_php] tags into an eval() function. The code in the eval() function won’t reference PHP code outside the function.

    This will work:

    [insert_php]
    function is_single() { return true; }
    if (is_single()) {
    echo '<p>Some text.</p>';
    }
    [/insert_php]

    But it won’t work if it’s broken up into separate [insert_php]…[/insert_php] chunks.

    Will

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Manually specified HTML between PHP’ is closed to new replies.