Migrated my joomla site to WP. The images were in a folder named 'asets' in joomla site. I copied the dir to wp and images work fine while url structure is raw.
But if I change the url permalink, the link to images also change.
like
sitename/?p=123 image path = sitename/asets/imagefile this works.
sitename/samplepost image path = sitename/post-name/asets/imagefile image not found
sitename/archive/123 image path = sitename/archive/asets/imagefile image not found
Please help me to solve this problem.
Just use absloute path or relative path with slash at start of path to get the root path.
I guss your HTML code look now like this:
<img src="assets/imagefile.jpg" alt="" />
So is it a relative path, the browser add the src to current url.
But if you change this to relative path from root it's will be work:
<img src="/assets/imagefile.jpg" alt="" />
Or using full absolute path:
<img src="http://example.com/assets/imagefile.jpg" alt="" />
All about HTML file paths
More important thing, in wordpress you must to work only in theme directory scope And use get_stylesheet_directory_uri() function.
Your code need to look like this:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/imagefile.jpg" alt="" />
Related
I'm creating a wordpress theme. and i want some of the images to remain static. how can i get the url behind my image source.
My Default Image URL
<img src="assets/logo/logo.jpg">
I was trying <img src="../assets/logo/logo.jpg">
Is there any function of wordpress that we can use to get the url of an image?
You need to get the full path of the theme folder too you can do it like this
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/logo/logo.jpg">
What I want to do is check in my template file (list.phtml, the product list), if an image exists or not. I can output an existing image like that:
<img src="<?php echo $block->getViewFileUrl('Images/imagename.png'); ?>" alt="">
My problem is: before showing that I want to check if that image exists. But of course file_exists only takes a relative path and I cannot find out how to get a relative path for my image. Is that possible in magento2 and if so - how?
I am using PHP to upload images in my web application. The images are stored in some directory on the server while their paths are stored directly in MySQL database.
The upload goes very well and images get in the folder but the problem is accessing thoses images with their path field stored in the database : i am not yet able to find the correct form of the path i should use, now am using the realPath and dirname functions to help me get the path so finally an example of path is C:\wamp\www\webroot\img.png (since am on Windows using wampserver) So when i do something like :
<img src="$image->path" />
i get no image shown in the browser and when i inspect it i get the expected code like :
<img src="C:\wamp\www\webroot\img.png" />
which means that this path format is not correct to show the image.
I have tried many things : i took the same path and acced it with the browser and it showed me the image (with the file protocol automatically) so i added file:// to the image path but nothing was new. I have also tried to acces it as a web url and with that it goes will for example it shows the image when putting
localhost/webroot/img.png
But what i need exactly is being able to store and retrive the image file again. So is it a file system probelm ? is the code platform independant ?
I will be very grateful for any help
Thank you.
You can't show an image with its path, but with its URL.
In PHP, we use to save the filename only in MySQL and after, you display the image with <img src="path/to/img/<?php echo $image->filename; ?>" />
That's all!
Add the file protocal to your path.
<img src="file:///<?php echo $image->path; ?>" />.
The best thing you could have to done is save the image in a folder inside your project/website folder. Then save the path to the image from the root folder in the DB.
Example: I uploaded a an image of filename "image.png" inside "Img" folder in the Website Root Folder. Then I will save "Img/image.png" inside my DB.
So anytime I want to reference the image, I will just use
<img src="/<?php echo $image->path; ?>" />
Or
<img src="<?php echo $image->path; ?>" />
Sorry for wasting your time, i have solved the problem. It was an issue with how my application is accessed. It should be accessed from only a directory called web so every path should be referenced from that directory !!.
All the Images of the website doesn't appear.
If I access the default url, specified in config file, under the base_url, all the images have shown.
But when I access this url (127.0.0.1/dcm/Controller/Index), not even a single image is retrieved.
I think it's a path problem, but I can't figure it out properly.
Here's my root folder structure (I'll try to make it understandable):
css
dcmapp -> Here I have my views
dcmsys
htmlconstants -> Here are my header and footer, common in all pages
Images -> Here are all the website images
Scripts
For example, in my header.php in htmlconstants folder, I have this code, for example:
<img src="<?php base_url() ?>Images/fbic.png">
<img src="Images/phone.png">
<img src="Images/email.png">
As you can see in code, I'm trying to use a base_url function to see if I can get the full path till the image, with no success.
In my Views, the same thing.
instead of
<img src="<?php base_url() ?>Images/fbic.png">
try this:
<img src="<?php echo base_url(); ?>Images/fbic.png"></img>
I am new to MAMP and I am developing a theme I designed. However I can't seem to get the images to render. I am using a clear theme I got from starkerstheme.com
When adding an image directly to the code I used:
<img src="<?= $theme ?>/images/logo.png"/>
But the image is not showing up, also I tried to add it to the media library and it's still not rendering.
This works for me:
<img src="<?php echo get_bloginfo('template_url') ?>/images/logo.png"/>
See get bloginfo() function for more info.
You can use the following code to add an image. This works for me:
<img src="<?php echo get_template_directory_uri(); ?>/images/filename.png">
<?php echo get_template_directory_uri(); ?>
as suggested gets the PARENT theme, which is OK but if you've developed a child theme (as recommended by WordPress people) you need:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/Logo.png">
Just go to your dashboard and upload your picture in the media section, then select it you'll see the image options .. then copy it's url
<img src="your/copied/url"/>
This aslo works for me in localhost
You might need to do the full <img src="<?php echo $theme; ?>/images/logo.png"/>
Update I didn't read your question closely enough. If you're using the media library for the image, you'll need to specify the actual path to the image. You can figure this out from within the media library, but it's probably site_url/wp-content/uploads/2012/01/filename.jpg
In short, if you uploaded it in media, it wouldn't actually be in your theme.
<?php bloginfo('template_directory'); ?>/
use for internal root folder in images to place on theme on wordpress.
The forward slash is needed for the image to show
Remove the = after <?
<img src="<? $theme ?>/images/logo.png"/>
in fact, I'd probably do something like this:
<img src= <?php $theme ?> . "/images/logo.png"/>
on 2021...
Just name the image as screenshot.png [ recommended image size (currently) is 1200px wide by 900px ] and put it on theme's top-level directory (where the style.css file is )
and that's all you need to do.