/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//The first thing to do is to paste this code on your functions.php file: function image_shortcode($atts, $content = null) { 'name' => '', 'align' => 'right', 'ext' => 'png', 'path' => '/wp-content/uploads/', 'url' => '' ), $atts ) ); $file=ABSPATH."$path$name.$ext"; 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 { return ''; } } add_shortcode('image','image_shortcode'); /* Once done, you can use the image shortcode in your posts. For example, the following line of code: [image name=cat] */
URL: http://www.wprecipes.com/wordpress-shortcode-automatically-insert-image-by-file-name