WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following code for showing images using the shortcode image but the shortcode is [image name=logo] to load an image from /uploads/ directory called logo.png; changing the name I can load different images just like dog.png bullet.png etc. writting after name= the name file.

So my question is how to make the function to write on shortcode [logo] and I can get the image logo.png

function image_shortcode($atts, $content = null) {
extract( shortcode_atts( array(
    'name' => '',
    'align' => 'right',
    'ext' => 'png',
    'path' => '/wp-content/uploads/',
    'url' => ''
    ), $atts ) );
    if (file_exists($file)) {
        if ($size!==false) $size=$size[3];
        $output = "<img src='".get_option('siteurl')."$path$name.$ext' alt='$name' $size align='$align' class='align$align' />";
        if ($url) $output = "<a href='$url' title='$name'>".$output.'</a>';
        return $output;
    else {
        trigger_error("'$path$name.$ext' image not found", E_USER_WARNING);
        return '';
share|improve this question
up vote 2 down vote accepted


'name' => '',


'name' => 'logo',

Then when there is no name field passed to the shortcode, it will default to logo, which will load logo.png.

share|improve this answer
Thanks! all it worked perfectly, also I change the line add_shortcode('image','image_shortcode'); to: add_shortcode('logo','image_shortcode'); just for user friendly usage :) now I type [logo] and logo image appears. – Fernando Baltazar May 10 '13 at 16:39
Oh yeah, I didn't see that. Glad it's all working :) – George Pearce May 10 '13 at 17:11

Your Answer


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.