5

I quite often run into a situation where I develop a site on a staging domain, have my client fill it there with content, and then when everything's approved move it to production. Now, my installation is quite portable (permalinks, assets are all fine), and I have environment-specific configuration, the only thing that doesn't adapt to the environment is when a client links to a post from another post through the popup in the editor. These links appear to be just hard-coded in the HTML.

Is there a way to make these links relative to the url without effort on my client's side?

Thanks!

3
  • 1
    While this isn't the answer you're looking for, whenever I move a domain I end up also running a database update which runs through the post_content and changes any links: update wp_posts set post_content = replace( post_content, 'stagingdomain.com', 'actualdomain.com' );
    – Howdy_McGee
    Commented Nov 25, 2014 at 14:56
  • I do something similar to Howdy_McGee. You could create a small plugin that you install during development that updates the content each time a post is saved to replace local hard-coded links with relative links. Commented Nov 25, 2014 at 19:17
  • You might also consider a tool like WP Migrate DB Pro for your migration from staging to production server. Part of the migration process can include a search and replace. Commented Nov 25, 2014 at 19:41

2 Answers 2

2

WordPress is strongly opinionated about using absolute URLs. Doesn't mean it's better but it's a choice is makes.

The common way to handle it is replace as necessary in database. Please note that if you run replacement on all of database it is extremely important to use serialize–aware tool, or you risk corrupting the data.

2

I usually use tool like this: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

This takes care of any serialized data and can be used to change out staging data from the entire database, not just the post content.

Typically a search and replace will look like this: find = staging.site.com and replace with = www.site.com. This is a fast and reliable tool, and I've used it on dozens of client sites.

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.