I have a shortcode that creates an "opinion box".

The user should insert 4 parts

  1. the title
  2. the images
  3. the opinion
  4. side of the image in relationship with text

i want to check if no image was entered and in such
a case take a default image from /images/ folder...
but to do so without changing the 'paste Img Url'
statement which i need in order to explain to the
user where to put the image if exists.

This is the shortcode:

function opinionBox( $atts, $content = null ) {
    extract( shortcode_atts( array(
        'title' => 'yourtitle',
        'imgURL' => 'paste Img Url',
        'side' => 'left'
    ), $atts ) );

    return '
    <div class="opinionBOX">
        <div style="float: '. $side .';" class="myimg">
        <img alt="'. $title .'" src="'. $imgURL .'">
        <div class="speakerBOX">
            <span class="highlight_black">'. $title .'</span><p></p>
            '. $content .'
        <br style="clear: right;">
add_shortcode( 'opinionbox', 'opinionBox' );
  • if ( 'paste Img Url' === $imgURL ) $imgURL = 'default.png'; ... or did I missunderstand you?
    – kaiser
    Mar 29, 2012 at 20:57
  • 1
    No, you didnt i actually did @michael solution but with a type Error and didnt catch that at all even after starring at the code for a while... since i have little expirence with shortcodes i was sure missunderstood the logic behind a shortcode - i guess silly happens once in while ;) thanks for your time
    – Sagive
    Mar 29, 2012 at 21:15

1 Answer 1


add a conditional statement before the line with 'return', for example:

if( $imgURL == 'paste Img Url' ) $imgURL = get_stylesheet_directory_uri().'/images/default.jpg';


  • If not using STRICT type checking, you should use »yoda conditions«.
    – kaiser
    Mar 29, 2012 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.