what is the path of the image? - wordpress

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" />

Related

why does relative path is not working for <img src="""> in wordpress

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.

WP - child theme get the theme directory

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" />

Insert logo header.php wordpress

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" />

How to use an image from the folder wp-content\images from a php file?

I have a Wordpress website that was customized by a php developer. He created a folder for images in the root of the website. I have a requirement to move this foder from the root of the website to inside the wp-content\images\ folder.
Here is how the php file is written today using the image files from the folder in the root:
<img src="images/img1.jpg" border="0" style="padding-right:44px;"/>
<img src="images/img2.jpg" border="0" style="padding-right:44px;"/>
<img src="images/img3.jpg" border="0" style="padding-right:44px;"/>
<img src="images/img4.jpg" border="0" style="padding-right:44px;"/>
<img src="images/img5.jpg" border="0"/>
Now that I moved the images to the wp-content\images\ folder, I tried many combinations (wp-content/images/img1.jpg; /wp-content/images/img1.jpg; public_html/wp-content/images/img1.jpg;/public_html/wp-content/images/img1.jpg), but the images are not showing up. How should I refer to the images in that folder?
Many thanks!
Rob.
If your images are associated with a custom theme then they should be in your theme directory.
You can use the get_bloginfo wordpress api to get an absolute url to this directory.
bloginfo('template_url')
See the above link for important information on different variations of this.
So you would replace your image links with something like
<img src="<?php bloginfo('template_url')?>/images/img1.jpg" border="0" style="padding-right:44px;"/>
Add Image Directory to Active Theme
Add /images folder to your current active theme.
Add Local Image Directory to Active WordPress Theme (Child)
Optimize Your Images for Production
This is important for user experience and pagespeed. A faster website shows visitors you care about their time. If using the native media manager, there are several free plugins that will optimize your images automatically on upload-- in addition to online services (like TinyPNG), OS applications (like Codekit for Mac, JPEGMini for Windows) and the command line.
Display Local Image in WordPress
If Parent Theme is active: use template_directory
<img src="<?php bloginfo('template_directory')?>/images/YOUR-IMAGE-HERE.jpg" alt="Image Title" border="0" width="" height="" style="padding-right:44px;"/>
If Child Theme is active: use stylesheet_directory
<img src="<?php bloginfo('stylesheet_directory')?>/images/YOUR-IMAGE-HERE.jpg" alt="Image Title" border="0" width="" height="" style="padding-right:44px;"/>
Add this code to your template files where you want your image to display, changing '/images/YOUR-IMAGE-HERE' (and attributes) to match the correct file location, name and attributes:
Include alt, width and height information for every image in production to increase pagespeed and enhance content accessibility.
That's it!
Additional Notes
If using a child theme, you'll want to change template_directory to stylesheet_directory
In most cases you'll want to use the native WordPress media manager to insert and display images. There are also several free plugins that can help you optimize and enhance image quality dynamically:
EWWW Image Optimizer
WP Retina 2x
Regenerate Thumbnails
In addition, WordPress has a list of available parameters that can be used to target a specific (different) directory or url. Check that our here:
http://codex.wordpress.org/Template_Tags/bloginfo
Include image set as separate file for reuse
If reusing this same 'set' of images in several places, create an include file for the set and add them via [shortcode] as needed. To update, you would then only need to update the extended file, which would in turn update all exported code where the [shortcode] has been placed automatically.
<?php include( get_template_directory() . '/includes/myfile.php'); ?>
Best, -K

WordPress file right there, cannot be found!

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="" />

Resources