WordPress.org

Forums

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

  1. estr
    Member
    Posted 2 years ago #

    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/

  2. WillBontrager
    Member
    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.

    [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

  3. estr
    Member
    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

Tags

No tags yet.