Can anyone tell me,how to show an image via shortcode.I mean when I use my shortcode,an image will displayed.(shortcode example: [smile] and image location mytemplate directory/images/smile.png)Sorry for my week english.

  • What has been your research so far? Sharing your research helps everyone. Tell us what you found and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and above all, it helps you get a more specific and relevant answer. More info about how to ask a good question can be found on the How to Ask page.
    – kaiser
    Jan 14 '14 at 13:44

This is basic function to create a shortcodes.

Put this code in your functions.php

function smile_shortcode() {
    $output = get_template_directory_uri() . '/images/smile.png'; // put your smile image here
    $_image = '<img src="' . $output . '">';
    return $_image;

Then go to your dashboard and post editor. Remember to put [smile] in your post.

More: http://codex.wordpress.org/Function_Reference/add_shortcode

  • Thanks you so much @ucon89.It's working.Really to speak,I am new to php.
    – S.k.joy
    Jan 14 '14 at 14:16
  • you are welcome. Oya, mark my answer to set approved/accepted. So people can learn from it. :)
    – ucon89
    Jan 14 '14 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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