Right way to get image path

Called the images in my theme as shown below

<img src="<?php bloginfo ('stylesheet_directory');?>/images/blogo.png" />

It worked perfectly until I installed a Child Theme. I had to change

<?php bloginfo ('stylesheet_directory');?>

to

<?php bloginfo ('template_directory');?>

Before it started working again. Just need help understanding why that happened. Thanks

Solutions

Stylsheet directory links to the main stylesheet, and not the child theme( since the child theme may not contain the style.css by default, it inherits the style.css of parent theme. So the parent path is called if you are using this).

So always use get_stylesheet_uri() or get_template_directory_uri() for these purpose.

Hope this clarifies you.

stylesheet_directory is the directory that contains the main stylesheet in use (so if you have a child template then it would be the child directory. If not, it will be the template directory.

template_directory is the directory of your parent theme.

Look at the codex for more details

Similar questions

Slider showing the right content but not leading to the right permalink
I'm using a custom Wordpress theme which is Goblog theme, in which a slider is included (it's not a plugin). The slider worked fine untile one day it stoped working correctly. The only change I could have done about the slider was editing the CSS to add more height, which, I think, isn't the cause of this issue. Basically everything works great on ...
Apply the right content to a modal with jQuery and the right button id's
So lets be straight to the point; I am using a WP theme and obviously it has some widgets in it. Now I want to add 1 button to each widget. Var instance would be the widgets so I only add buttons aslong as there are widgets. The a tag is designed to be a button. For each(?) button the id should +1, so Widget 1 would contain a button with ID="stats0...
Align right input form in wordpress right sidebar
I have a MailChimp for WordPress plugin with form code as such It looks like this on the sidebar: It seems everything is correctly right aligned within the sidebar except my input form. There is a right margin that I cannot get rid of. I can put customer CSS like so, but it doesn't so anything. Any tips to edit either the HTML or the custom CSS to ...
bloginfo no show the right path
I use bloginfo( 'stylesheet_directory' ) for show the link to css styles , in localhost in my computer i can see the url right as http://127.0.0.1 , etc The problem it´s inside of domain , i see the DOM and see that no show http:// only show domain.com and by this no let me the css load , if i add http:// until of this function works all and if no ...
WordPress opens js files as a catalog. Path is right
When I import external js file everything is okay.. no matter if I import it by <script> tag or by wp_register_script function but when i try to import local file everything crashes. Firstly I had doubts about path I entered so I've opened Web Inspector in Opera and compare path I've entered with real path. The same. Unfortunately WordPress d...
wp_upload_bits() is not giving the file path right in localhost
I'm trying to upload files into a separate directory inside the uploads/, and I succeed using wp_upload_bits(). I's happy with everything and I thought thing was done. But when I's trying to delete the files, as I din't use wp_add_attachment() etc. so I need to unlink() the file using its path. So I stored the file array. When I's trying to use the...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.