• Resolved jvwx

    (@enfueggo)


    I hope/assume this can be done in PHP, but I’m not sure how…

    I have a variable in a Post Snippet, such as:
    <div>Some text. <span>And here's my {variable}</span></div>

    Is there a way to NOT display the <span>‘s if the variable is not provided?

    Thanks so much!

    http://ww.wp.xz.cn/extend/plugins/post-snippets/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Yes, by making it a PHP snippet you can achieve that. Taking the snippet you posted, and changing it to this, should work:

    echo "<div>Some text.";
    if ("{variable}" != "") {
        echo "<span>And here's my {variable}</span>";
    }
    echo "</div>";

    Cheers,
    Johan

    Thread Starter jvwx

    (@enfueggo)

    Beautiful. Love the plugin and this just made it 10x more useful. Thanks SO much!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Display content only if variable is provided’ is closed to new replies.