• Hidoshi

    (@hidoshi)


    My familiarity with PHP is a little rusty right now. I’m trying this:

    <?php
    if ( has_post_thumbnail() ) {
    	echo ("<div class="content-left" style="background-image:url( '" . $image_url[0] . "' );"></div>");
    }
    else {
    	echo 'Blah';
    }
    ?>

    Which, according to my hack-together understanding, should get me an if/else situation where the background image gets pulled from the post thumbnail, or it just prints “blah” if none is available.

    Now, the code for the post thumbnail is fine. It works properly. Introducing the if/else PHP, however, has broken it. I feel like I’m just missing a key piece of syntax in here. Anyone have any ideas? Thanks!

Viewing 1 replies (of 1 total)
  • esmi

    (@esmi)

    You need to review using single & double quotes in PHP. Try:

    <?php if ( has_post_thumbnail() ) echo '<div class="content-left" style="background-image:url( ' . $image_url[0] . ' );"></div>';
    else echo 'Blah';?>
Viewing 1 replies (of 1 total)
  • The topic ‘Echoing PHP inside of PHP with a link’ is closed to new replies.