Reputation: 51
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.
Upvotes: 0
Views: 162
Reputation: 701
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="" />
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="" />
Upvotes: 1