Prevent Yoast from removing the canonical tag if robots meta tag is set to noindex [closed]

Assuming this is an XY problem and the original question is: “How do I block crawlers from indexing my staging site?”

Staging and production should be as close as similar. Having changes in code would be a big “no no” for me (except for some environment variables, e.g. setting WP_ENVIRONMENT_TYPE or db credentials).

Instead, I would suggest setting up the webserver to serve the X-Robots-Tag with noindex. There was some discussion which takes preference if you have both (X-Robots-Tag and <meta name="robots" />), but in my experience it suffices to have X-Robots-Tag: none to not have the sites indexed, even if their own <meta name="robots" /> differs.