Return to Snippet

Revision: 51075
at September 14, 2011 00:08 by distribuida

Initial Code
//The first thing to do is to paste this code on your functions.php file:

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 '';

Once done, you can use the image shortcode in your posts. For example, the following line of code: [image name=cat]

Initial URL

Initial Description

Initial Title
WordPress shortcode:  Automatically insert image by file name

Initial Tags

Initial Language