Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wordpress get_template_directory

I have the following code, what I am expecting it to do is locate the theme I am using and place that path before the /images/bg.png so far I just get the location which is localhost/nameoffolder/images/bg.png but what i want is localhost/nameoffolder/wp-content/themes/images/bg.png

<img src="<?php get_template_directory(); ?>/images/bg.png"></img>

this is the directory I would like to display http://localhost:8888/fiftyfity/wp-content/themes/fiftyfity/images/

like image 439
Cool Guy Yo Avatar asked Jun 29 '26 03:06

Cool Guy Yo


2 Answers

I used this code instead and it worked

<img src="<?php bloginfo( 'template_directory' ); ?>/images/bg.png"></img>
like image 89
Cool Guy Yo Avatar answered Jul 01 '26 19:07

Cool Guy Yo


get_template_directory() returns the directory, but it doesn't echo it.. so if you use it with echo it will work

<img src="<?php echo get_template_directory(); ?>/images/bg.png"></img>

but I will suggest to use get_template_directory_uri() instead, because above will not be portable ( windows use backward slashes as separator )

<img src="<?php echo get_template_directory_uri(); ?>/images/bg.png"></img>
like image 23
DevC Avatar answered Jul 01 '26 20:07

DevC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!