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

How do i reference images in a page/post without installing the php plugin or typing it out manually like this:

share|improve this question

Use get_template_directory_uri()

print get_template_directory_uri() . '/image.jpg';

In child themes use get_stylesheet_directory_uri() if you have replaced the image.

In a shortcode this would look like this:

/* Plugin Name: Theme URI Shortcode */

add_shortcode('theme_uri', 'wpse_66026_theme_uri_shortcode' );

function wpse_66026_theme_uri_shortcode( $attrs = array (), $content = '' )
    $theme_uri = is_child_theme()
        ? get_stylesheet_directory_uri()
        : get_template_directory_uri();

    return trailingslashit( $theme_uri );
share|improve this answer
that looks like a php command, how would i post php into pages? is there another way of doing it like shortcodes? – Sarmen B. Sep 23 '12 at 16:19
Sorry, I misread your question. See my update. – toscho Sep 23 '12 at 16:27
does that shortcode already exist? or i have to put it myself? and does it go into the functions.php file?(in the themes folder) thnx – Sarmen B. Sep 23 '12 at 16:37
Put it into a plugin. Otherwise the content will be broken after a theme switch. Shortcodes should never go into theme files. – toscho Sep 23 '12 at 16:45

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.