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.

Whenever I use a JavaScript path to /images/imagename.jpg or within CSS ie.

background: url(../images/imagename.jpg)

works fine sitewide giving me an expected path to an image that looks like this:

http://localhost/projectname/wp-content/themes/bonestheme/library/images/imagename.jpg)

The problem is that that path on custom post type pages becomes:

http://localhost/projectname/post_type/page/wp-content/themes/bonestheme/library/images/imagename.jpg)

Can someone help me understand this and how to fix it? Thanks in advance.

share|improve this question

1 Answer 1

I don't get the exact scenario you are talking about, but you can try this:

First, you should get the url of your theme directory using

get template directory()

and just print the path it is getting for you using

<div> <?php echo ''.get_template_directory(); ?> </div>

, and relative to that you can add your image's path (NOTE: It gives path without the trailing slash), like this:

get template directory()."/images/imagename.jpg"

assuming you have images folder inside your themes folder.

NOTE: In the case a child theme is being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory.

share|improve this answer
    
Yes I'm aware of get_template_directory. However this is strictly a CSS and JavaScript related issue. –  BenRacicot Jun 27 at 11:45

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.