Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am manipulating an img element in functions.php using jQuery by changing the src attr on hover. How do I make so the absolute path works? Currently, when I view the image directly in the browser it brings me to 404 page. Relative path doesn't work either.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

i always start every theme w/ some constants

` define('THEME', get_bloginfo('stylesheet_directory')); //or you could use this one: //define('THEME', get_stylesheet_directory_uri());

define('IMAGES', THEME . '/images'); `

and some others, but the point is that at any place in my code i can point to my theme's image folder

img src = "<?php echo IMAGES . '/image.png';?>"

share|improve this answer
    
Yah that's another way of getting the relative path. But like I said it doesn't work. But if I host the image in another site and use their link, the img displays fine. Maybe it's because of thematic theme? I know I could just switch to another theme to find out but I don't want to break things as of now. –  jilseego Jun 29 '11 at 6:15
    
doubt it is a thematic issue, i use this w/ thematic all the time. should produce a link like mysite.com/wp-content/themes/mytheme/images/image.png which isn't a relative link. from codex on get_bloginfo 'stylesheet_directory' - Returns the stylesheet directory URL of the active theme. (Was a local path in earlier WordPress versions.) Consider using get_stylesheet_directory_uri() instead. so you could define('THEME', get_stylesheet_directory_uri()); what do you get in your markup (view source) for the image source. that is more telling than "it doesn't work" –  helgatheviking Jun 29 '11 at 6:25
    
You are right it works! Maybe I was too sleepy yesterday! :-) Now the problem I am facing is how to do that with jQuery but that's a different question already. Thanks! –  jilseego Jun 29 '11 at 8:47
    
if you inject your jquery in the header or footer you can still process the php. if you have it in a js file that won't work. >>> var src = "<?php echo IMAGES . '/image.png';?>" –  helgatheviking Jun 29 '11 at 14:35
    
didn't know that! thanks! –  jilseego Jun 30 '11 at 16:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.