Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
        <div class="speakerBOX">
            <span class="highlight_black">'. $title .'</span><p></p>
            '. $content .'
        </div>
        <br style="clear: right;">
    </div>
    ';
}
add_shortcode( 'opinionbox', 'opinionBox' );
share|improve this question
    
if ( 'paste Img Url' === $imgURL ) $imgURL = 'default.png'; ... or did I missunderstand you? –  kaiser Mar 29 '12 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 SEO Mar 29 '12 at 21:15
add comment

1 Answer

up vote 1 down vote accepted

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

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

http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

share|improve this answer
    
If not using STRICT type checking, you should use »yoda conditions«. –  kaiser Mar 29 '12 at 21:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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