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

this is really a two part question, neither of which I can find the direct answer to.

(1) What's the correct way to link assets like buttons or include files like JS? Currently, the src attr for things like this is set to:

src="<?php bloginfo('template_url'); ?>/path/to/my/file.xxx"

Is that correct for deploying my site to production? In other words, it shouldn't really matter if it's www.mysite.com or www.mysite.dev because the PHP snippet will render to whatever the site URL is, right?. Currently it's in a staging environment with that top-level (but fake) .dev domain.

(2) For navigation and other text links, is it okay that I use relative paths in the href attr? Is there a reason I should use absolute paths instead? Is there a SEO reason? I ask because right now my development URL (as mentioned above) is www.mysite.dev, so if I use absolute paths, I will have to go through and change each one to .com before deploying to production, which I don't want to do.

Note: In case you're wondering, I am using DesktopServer from ServerPress as my Wordpress dev environment.

share|improve this question
up vote 0 down vote accepted

For general links use home_url().

<a href="<?php echo esc_url( home_url( '/path/to/link' ) );?>">Anchor</a>

To link to theme assets like images etc use get_stylesheet_directory_uri().

<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/your_image.png" />

You could just as easily use relative links for navigation but I would stick with home_url() for consistency.

share|improve this answer
Thank you @Chris_O – Mark Bubel Jun 13 '12 at 20:24

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.