Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

domain.com/wp-content/themes/mytheme/image.jpg
share|improve this question
add comment

1 Answer

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:

<?php
/* 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
1  
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
add comment

Your Answer

 
discard

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.