How do i reference the theme path in pages for images?

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

Related posts

Leave a Reply

1 comment

  1. 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 );
    }