This isn’t a problem but rather I am just curious to see how others are using this function. The codex does not really say a preferred method of use although it does provide some straight-forward examples.
For example if my domain is example.com
I can write any of these:
<a href="https://wordpress.stackexchange.com/questions/224062/<?php echo esc_url( home_url() ); ?>/example">Example Page</a>
<a href="<?php echo esc_url( home_url("https://wordpress.stackexchange.com/") ); ?>example">Example Page</a>
<a href="<?php echo esc_url( home_url('/example') ); ?>">Example Page</a>
<a href="<?php echo esc_url( home_url('example') ); ?>">Example Page</a>
<a href="<?php echo esc_url( home_url('example', 'relative') ); ?>">Example Page</a>
And they will all output the same result (simplified) :
<a href="https://wordpress.stackexchange.com/questions/224062/domain.com/example">Example Page</a>
I use the third example given most often and I understand the use of the last example, as at times I need to link to a secure page (https://), but what is the point of the other accepted variations?
Is one method considered a “best practice” or is it just left up to personal preference?