Is there a way to do normal links in WordPress (not image source links) in a "relative" manner??

Im doing custom site in WP and some portions of the site, for example an image link that when clicked, leads to a specific dynamically built WordPress page, i always link them absolutely.

So for example, if the website wordpress page i want link to is page_id=39 and the site is XYZ.com then my image link would be etc...

Problem with this is that when i take the site from a test server to the live server i have to manually go in again and redo ALL the manual links.

Unlike the image relative links which look something like this <img src="<?php bloginfo('template_directory');?>/image here"/> where this relatively looks for physical image somewhere on the site, the WordPress pages don't exist in the traditional sense of an actual page.php etc so, how can i get around this, is there some function i can employ that will get me using relative links/path builder to actual dynamic wordpress pages so that i dont have to manually/absolutely link something?

Thanks in advanced.

1 Answer 1


There's a couple of things that you might be able to do here depending on how you are creating your links. Are you talking about page content or are you working in the theme template.

If in the theme template you can do use the <?php bloginfo('url'); ?> to get the base path of the blog. That will change from server to server.

If in the page content you can start your link with the backslash / character before the relative link. That should keep your links relative to the server.

Does that help?

Another option would be to run a replace function on all links in the database after you've migrated the site over to the new server. It's a very easy script to run from PHP MY ADMIN.

Something like this:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'staging.server.com', 'www.productionserver.com');

(credit to Barry Wise)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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