How do I load the contents of a text file – or any other file, like .php – and use the test for the login_message
hook that prints a message above the #login
box in wp-login.php?
(BTW, this is in a child theme, if it makes a difference.)
function custom_login_message() {
$message = get_bloginfo('stylesheet_directory')."/tos.txt";
return $message;
}
add_filter('login_message', 'custom_login_message');
Right now, the function above prints out the URL of the file, not the text in the file, i.e.:
Use
locate_template()
if you want to use a file from your theme.include()
orrequire()
works too.Sample code, tested:
Your function just constructs the URL. You’d need to
include
the file to get at its contents. You may be able to do this withget_template_part
. I am not sure about the hook context. However, your file would need to generate a PHP variable or it will echo immediately rather than return.If you are using a text file, you could look into one of PHP’s file functions, like
get_file_contents
for more complicated manipulation of the file contents before your echo/return it. Or use output buffering.