Insert PHP
[resolved] Manually specified HTML between PHP (3 posts)

  1. estr
    Posted 2 years ago #


    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!


  2. WillBontrager
    Plugin Author

    Posted 2 years ago #

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


    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:

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

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


  3. estr
    Posted 2 years ago #

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Insert PHP
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.