Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
Have you access to the directories of your website?
What do you mean access? I’m using WordPress locally for now. I’m using WAMP
Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
Can you create a directory within your theme, name it relevantly and put all your images in there? Then you can specify that directory in your URLs.
Yes, i think i already have created a folder inside my theme
WordPress/wp-content/themes/myTheme/images/ (this is where my images at)
So the img src will be like
<img src="images/image1.jpg" />
right? but this one doesn’t work
Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
Try
/wp-content/themes/yourThemeName/images/image1.jpg
Tried /wp-content/themes/yourThemeName/images/image1.jpg
doesn’t work :`(
i wonder if there’s a plugin that can do that
instead of http://localhost/wordpress/wp-content/uploads/2012/10/image1.jpg
it will accept
images/image1.jpg
i really need a help on this ..
because i have a lot of mini icons that are in unordered list. do i have to upload them and copy paste the url one by one? that will take me at-least a day to complete it.
Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
Did you try replacing yourThemeName
with your actual theme name?
Yes i did,
actually it’s like this
/wp-content/themes/mysite/images/miniperson.jpg
also tried this
wp-content/themes/mysite/images/miniperson.jpg
/mysite/images/miniperson.jpg
mysite/images/miniperson.jpg
/images/miniperson.jpg
images/miniperson.jpg
/wordpress/wp-content/uploads/2012/10/image1.jpg
wordpress/wp-content/uploads/2012/10/image1.jpg
/wp-content/uploads/2012/10/image1.jpg
wp-content/uploads/2012/10/image1.jpg
none of them seems to work
I think this might be a bit overkill, but you could try using shortcode.
Add this to your functions.php
:
// Create the shortcode
function template_url( $atts, $content = null ) {
return '<img src="'. get_template_directory_uri() .'/'. $content .'" alt="" />';
}
// Add as shortcode
add_shortcode("template", "template_url");
To use it, you could simply type this in your WordPress visual editor:
[template]images/image1.jpg[/template]
Which would result as:
<img src="http://yoursite.com/wp-content/themes/yourtheme/images/image1.jpg" alt="" />
This isn’t tested though, so it may contain errors. But the basic should look like that. 🙂
Thanks Xaliber. Great piece of code. It worked out smoothly.