Is it better to store images and other files in the root directory or the theme directory

Of the two option you proposed, the latter is better for maintainability.

The reason is, if you ever need to move the site to another server or use the theme on another site, it seems an easier process to move / reuse.

If you’re not using the image for themeing, consider just using media library for post/page embeds.


Instead of:

bloginfo('template_directory');

Consider:

get_template_directory_uri();

or

get_stylesheet_directory_uri();

Source: https://developer.wordpress.org/reference/functions/bloginfo/#possible-values-for-show

tech