I have Wordpress deployed on Ubuntu server.
in the folder where my theme is I have index.php. In the same folder I have a file: "logo.png"
in index.php I have the following line:
<img src="logo.png" alt="" />
Yet, i get a broken image when browsing there. How can that be? The file is right there, sibling to index.php in the folder!
It's going to look for logo.png in the root directory of the website, not in your theme folder. You need to add the path to your theme directory to the image tag.
I got it, should have used:
<?php bloginfo('template_directory'); ?>
so that the right path is taken at runtime for my theme folder.
try something like this
<img src="<?php bloginfo( 'template_url' ); ?>/logo.png" alt=""/>
You can also specify the full path of the logo.png file in image source so that it will grab the logo image from the source rather then looking in your parent directory for the logo image
<img src="*Full path of logo.png file*" alt="" />
Related
I know the solution for this problem
The solution is to use "get_template_directory_uri()"
But Can someone please tell me why this relative path itself "/img/entry.png" is not working even though I'm using parent theme(Not child theme)
Before(Not working)
<img src="img/entry.png" alt="">
After(Working) → Why??
<img src="<?php echo get_template_directory_uri()?>/img/entry.png" alt="">
I putted index.php and Img folder at the same level in Theme folder as below.
So why "img/entry.png" is not working?
(Theme folder)
|
|--index.php
|--img
|-entry.png
get_template_directory_uri() adds the path of the directory in which img/is located. If you want not to add that function then you have to add the path manually.
For example if your WordPress instance uses a theme called my-theme then this /wp-content/themes/my-theme/img/my-image.jpg could be served to img's src.
the root of wordpress project is consisted od some directories such as 'wp-content' and 'wp-admin' and doesn't contain any folder named 'img'.
the 'src' attribute of images in HTML tag targets the root of the project then reads the url. so you should set your img folder path correctly from the project root.
I have an image folder in a child directory where some theme-related gfx is located. If I want to access it via:
<img src="<?php echo get_template_directory_uri();?>/assets/Logo.svg" />
It's trying to look for /assets in the parent theme directory.
How can I reference the child theme directory?
The function get_template_directory_uri always return the url of Parent Theme. Don't matter, where you called it.
To get the url of your Child Theme, you can use get_stylesheet_directory_uri(). So, your code will be:
<img src="<?php echo get_stylesheet_directory_uri();?>/assets/Logo.svg" />
Hello I want to insert my logo to my wordpress site
<img src=”/wordpress/wp-content/themes/test/images/logo.png”>
that is my FTP Path to the image but it's still does not work. When I refresh my site a image icon appears but it does not show my logo... Why? It seem that the PATH don't work right? Any suggestions what could be wrong or is there any special WP Query I need to use? Seems like it? Can't find tho..
Thanks
You shouldn't be using an absolute path to an image file. This would be useful if you wanted to get the files attributes in PHP but not when you want to show the image on the page.
There are two functions you should familiarise yourself with:
get_template_directory() - This will get the absolute path to the theme directory.
get_template_directory_uri() - This will get the theme directory URI.
Correct way to link to the image file:
<img src="<?php echo get_template_directory_uri(); ?>/images/logo.png">
Don't forget to add an alt attribute.
Use below function for site URL
site_url();
replace this with you img code
<img src="<?php echo site_url("/wp-content/themes/test/images/logo.png"); ?>">
use something like this
<img src="<?php bloginfo('template_url'); ?>/images/logo.png" />
i have created a custom static html page
by adding a php file in
wp-content/themes/myactivetheme/
containing essentially
<?php
/*
Template Name: test
*/
?>
<div><p>blablabla</p>
<div><img src="content/images/thumb/00500_Partition_Vivaldi_Printemps.jpg" /></div>
i have placed the corresponding image file in
wp-content/themes/myactivetheme/content/images/thumb
When creating a new page with the dashboard using this test template , the text is displayed but not the image, why?
Probably the source address for the image is wrong. Don't use relative links. For example:
Instead of:
<img src="content/images/thumb/00500_Partition_Vivaldi_Printemps.jpg" />
Use:
<img src="<?php bloginfo('template_url'); ?>/content/images/thumb/your-image.jpg" />
It will help Wordpress to find the exact path to display your image.
Relative URIs will be relative to your WordPress index, so WordPress will look for the image in the wrong place. You could
move the image
hard code the image url
do it the clean and right way, which is <img src="<?php echo get_stylesheet_directory_uri(); ?>/content/images/thumb/00500_Partition_Vivaldi_Printemps.jpg" />
the image file had to be placed in
/wordpress/content/images/thumb
I install wordpress in my pc.
the path of thr theme are C:\Program Files\Zend\Apache2\htdocs\www\www1\wordpress\Building_Child_Themes\wp-content\themes\BLANK-Theme\home.php
inside the folder BLANK-Theme there are folder cald images like wordpress\Building_Child_Themes\wp-content\themes\BLANK-Theme\images
inside the file home.php I have line <img src="/images/prod-sprunkler.png" alt="Image of Super Sprocket 1000" />
I can not sucsses to view the mage when the home.php are upload, in the adress bar I see http://127.0.0.1/www/www1/wordpress/Building_Child_Themes/
what I miss here ?
Thanks alot.
You have to use full path. You can take help of default functions to get the full path.
If the style.css file of your wordpress site is in the same directory, you can use the following.
<img src="<?php get_stylesheet_directory() ?>/images/prod-sprunkler.png" alt="Image of Super Sprocket 1000" />