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:


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


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


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.

  • Yes I'm aware of get_template_directory. However this is strictly a CSS and JavaScript related issue. – Ben Racicot Jun 27 '14 at 11:45



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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