How to use wordpress with any “site url” (the url in settings) for development?

There’s a bit more than just the option to update unfortunately. I’d recommend reading over https://wordpress.org/support/article/changing-the-site-url/ to learn about what is involved first. As far as plugin solutions, there’s lots that exist already, which would be a safer route than rolling your own. Better Search and Replace is a popular one.

Since you’re going to be doing this url change for client previews vs local dev vs production – I’d assume you either already have wp-cli or can easily get it up and running. It already has a built in search and replace you can do:

wp search-replace http://local.test https://throwaway-domain.com/subdirectory --skip-columns=guid --dry-run

From wp-cli documentation for search-replace, this script is useful as well:

# Bash script: Search/replace production to development url (multisite compatible)
#!/bin/bash
if $(wp --url=http://example.com core is-installed --network); then
    wp search-replace --url=http://example.com 'http://example.com' 'http://example.test' --recurse-objects --network --skip-columns=guid --skip-tables=wp_users
else
    wp search-replace 'http://example.com' 'http://example.test' --recurse-objects --skip-columns=guid --skip-tables=wp_users
fi

Note: You might have noticed the flag --skip-columns=guid in both examples, which is explained in the first link under Important GUID Note. Similarly the Better Search and Replace plugin mentioned has a checkbox to skip Replacing GUIDs.

As you mentioned you use docker in another comment, you can take a look at this StackOverflow question.