WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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 '14 at 11:45


share|improve this answer

Your Answer


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.