How do I convert my WordPress website to be domain agnostic?

Normally you never have to use your domain in your php code for plugins / themes. There are many functions like get_home_url() which automatically fetches the domain from configuration and is also protocol agnostic if you don’t force a protocol via the third parameter $scheme.

The function get_home_url() internally uses is_ssl() and the option value for home to decide which protocol to use.