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've been using custom fields for my wordpress theme, but i'd like to use shortcodes now for easier posting.

so before, in my index.php i have this:

<?php echo get_post_meta($post->ID, "Thumbnail", true);?>

how do i replace it with custom fields? SUch that i can just insert:

share|improve this question

A shortcode like this

[thumbnail height=100 width=100]http://urltoimage.com/image.jpg[/thumbnail]

Would need this type of setup

function content_insert_thumbnail($atts, $content = null){
    global $post;
    $thumbnail = get_the_post_thumbnail($post->ID, array($height, $width));
    $content .= $thumbnail; //Places the thumbnail after the content
    return $content; //Never echo a value from a shortcode function.
add_shortcode('thumbnail', 'content_insert_thumbnail');

To call this in your theme to insert your thumbnail:

$atts = array(
    'height' => 100,
    'width' => 100

This example doesn't make sense to place in your theme as you can just call the_post_thumbnail() function. However, this example is just to show you how to access the shortcode function (whatever it may be) in your template files.

share|improve this answer
how do u call this shortcode for my theme's index.php? – Zhianc Sep 18 '11 at 6:47
Just added an example to the answer. – Brian Fegter Sep 18 '11 at 18:58

I don't know whether this will work or not, but just try this code

function customfield_shortcode(){
 echo get_post_meta($post->ID, "Thumbnail", true);
//instead echo use return
add_shortcode( 'thumbnail', 'customfield_shortcode' );
share|improve this answer

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.