Calling an image within the theme folder from inside a post/page?

I realize that this was posted about 7 months ago, but in case you’re still looking for a solution to this, add this to your functions.php file:

/**
 * Add a shortcode for the current theme directory
 * @return string Current theme directory
 */
function yourtheme_get_theme_directory_uri() {
    return get_template_directory_uri();
}
add_shortcode( 'themeuri', 'yourtheme_get_theme_directory_uri' );

Then in the WordPress Editor you can simply use the [themeuri] shortcode to include the URL of your currently active theme directory.

Typically, you would want to include a shortcode like this as a plugin so that when you change themes the shortcode doesn’t disappear. However, because you’re using it to include media specific to your theme, I don’t think it matters.

And for those questioning why you would even want to do something like this: If the user who posted this question has theme-specific assets that need to be loaded in the Editor and might change but retain the same file name, this is a smarter, more future-friendly approach than using the Media uploader.

For example, in my own theme I have an SVG sprite that’s always named icons.svg but make include new icons or remove some over time. The sprite is generated as part of my Gulp build. An approach like this saves you from having to reupload and update URLs every time you update the sprite.