When WP_SITEURL and WP_HOME are set to different values - for example https://example.com/wordpress and https://example.com - the output links are inconsistent.

Thus, a permalink output will be relative to WP_HOME like https://example.com/my-url but if you call for something like a thumbnail url it will return a link relative to WP_SITEURL, such as https://example.com/wordpress/path/to/my-thumbnail.jpg

I'm aware that this is the convenient behaviour, but for this one use case I'd rather have it output relative to `WP_HOME - as in https://example.com/path/to/my-thumbnail.jpg - the reason being that I'm migrating an archive and I chose to symlink new folders to old rather then change the urls for the whole thing.

It could of course be done by wrapping all calls into regex functions but I was wondering if there's a more elegant, general setting in order to achieve this.

  • Well you're wanting to use those two fields in a way they weren't designed to. It wouldn't be easy. Regex isn't a bad idea. If it was specifically uploads that concerned you (like your thumbnail example), could you modify the upload_path option? You define an UPLOADS constant that it is the path of where uploads are stored (and from whence they are fetched). – tmdesigned Jan 23 '19 at 16:48
  • Would wp_get_attachment_image_attributes filter be useful in your case? Perhaps it could be used for modifying image urls. I got this idea from here, stackoverflow.com/questions/45571779/… – Antti Koskinen Jan 23 '19 at 17:07
  • @the_hobbes, The trouble with UPLOADS is that „This path can not be absolute. It is always relative to ABSPATH, therefore does not require a leading slash” which puts it under /wordpress by default, while messing with ABSPATH itself would most likely have unwanted consequences. – Lucian Davidescu Jan 23 '19 at 17:57
  • @AnttiKoskinen, looks like a better place to put the regex, right? Still better then what I had thought! – Lucian Davidescu Jan 23 '19 at 17:59
  • I don't know if it would work, but since it's a path, could you not start with "../" ? – tmdesigned Jan 23 '19 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.