0

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.

0

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.

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.