简体   繁体   中英

Difference between get_template_directory_uri() and upload images to wordpress site

I'm working with WordPress and I just want to understand the difference between uploading an image in your media folder on your WordPress dashboard in the media folder, and use the get_template_directory_uri(); to retrieve the theme directory and display images you have stored in your image folder like so:

<img src="<?php echo get_template_directory_uri();?>/img/image.png">

Are there any of these solution that is better than the other?

thank you

You should be thinking in terms of Is my content / resources static or dynamic?

If the resource is part of the theme (ie. static), you are best to use:

<img src="<?php echo get_template_directory_uri();?>/img/image.png">

If it is part of the content and can be changed by a WordPress user, then use the media uploads. An alternative is to use an options framework to allow the user to change static resources.

The difference is get_template_directory_uri() point directly to the current active template not to media folder. That's why called template directory .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM