Yes it is possible.
You will find lots of examples in other themes. Either temporarily switch themes, or install another WordPress using a different theme so that you can see how it works.
You need to use a browser inspector to examine your generated pages and hence fine tune your image code.
Thread Starter
beda69
(@beda69)
does not seem to be so.
I checked 80% of theme 2014’s files and the only I found was:
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
I use this:
<img alt="Brand" src="./images/icon.png" style="max-width: 30px;">
and if I use Brackets to code, and hover over that piece of code, correctly the image displays on hover
However, if I load the page in Firefox, image is broken and the console tells me “Could not load image” and the ONLY that works in console is if I change the
src="./images/icon.png"
part to:
<img alt="Brand" src="http://localhost:8888/mysite/wp-content/themes/mytheme/images/icon.png" style="max-width: 30px;">
and this is for sure not the way it should be achieved.
To you recommend to create a variable and then get it with a call to?
like
$imagepath = get_template_directory() . '/images/';
and then echo it?
I am not sure this is the good approach!
thank you
Thread Starter
beda69
(@beda69)
The only way I get this to work (I tested online to be sure)
<a class="navbar-brand" href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img alt="Brand" src="<?php bloginfo('template_directory'); ?>/images/icon.png" style="max-width: 30px;">
</a>
OR
<a class="navbar-brand" href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img alt="Brand" src="http://mysite.com/wp-content/themes/mytheme/images/icon.png" style="max-width: 30px;">
</a>
OR
<a class="navbar-brand" href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img alt="Brand" src="./wp-content/themes/mytheme/images/icon.png" style="max-width: 30px;">
</a>
According to all DOC i read, this should also work, but it does not
Not sure if this works only in CSS field though