the_field()
echoes out the result. You want get_field()
instead.
However these won’t automatically default to reading fields from the home page. You’re going to have to give get_field
the post ID of the home page to look up so it knows where to get the field from. Something like:
function alltomhobby_login_message( $message ) {
if ( empty( $message ) ){
$show_on_front = get_option( 'show_on_front' );
$home_page_id = ( 'page' === $show_on_front )
? (int) get_option( 'page_on_front' )
: ( ( 'post' === $show_on_front )
? (int) get_option( 'page_for_posts' ) : NULL );
if ( isset( $home_page_id ) ) {
$logintext = get_field( 'login_text', $home_page_id );
return $logintext;
}
}
return $message;
}
add_filter( 'login_message', 'alltomhobby_login_message' );
Or you could instead hard-code the page ID if you know it and it’s fixed.