You can use additional parameters while redirecting users from front-end.
i.e; http://yourdomain.com/wp-login.php?frontend=true
And get this parameter to check and determine whether the users have been redirected from the front-end or not.
if( isset($_GET['frontend']) && $GLOBALS['pagenow'] === 'wp-login.php' ) {
echo "<h2 id='fr-msg'>Message To display</h2>";
}
Use this code inside your function.php or in plugin. You can use css and javascript adjustments to display the message in correct position.
jQuery(document).ready(function(){
jQuery("#login").prepend(jQuery("#fr-msg"));
// Use as per your requirement.
}
This will have a dependency of jQuery hence it is necessary to include this script with a jQuery dependency. Include this in your function.php or plugin.
add_action( 'login_enqueue_scripts', function() {
wp_register_script('custom_script', [SCRIPT_URL]/customScript.js, array('jquery'),'4.2', true);
wp_enqueue_script( 'custom_script' );
} );