Search code examples
wordpresswordpress-theming

How to add images folders to local wordpress theme


Just starting out with WordPress and trying to create a theme from scratch based on an existing static website I have, all the guides and tutorials I have followed didn't mention anything on how to reference my images folder something like the way I used the enqueue function to add scripts and multiple CSS files. Attached is a screenshot of my current file structure

I already tried adding it in the head tag of my header file but none of the images show when I live preview the site, Inspecting element inspecting element on where an image is supposed to be shows that wordpress can't see the file. How can I add all the images in my folder at once and reference them appropriately when I need to use them?


Solution

  • This entirely depends on where you put the items. Typically if they are static theme specific images like css images or things that users won't have to access, I would create a folder called /my-theme/images/image.jpg

    The WordPress way to get the IMG URL is:

    <img src="<?php echo get_stylesheet_directory_uri();?>'/images/image.jpg'>