1

Is anyone aware of means to add html directly under the body tag on the wordpress login page, ideally using functions.php?

I'm aware of the various hooks and filters listed in the codex, but I have a use case which requires a simple line of html be present across the whole site and after several hours of research I'm no further forward.

2 Answers 2

3

If you look the wp-login.php file, you will see a hook login_header. So you add any custom content above the login form. Here is the example:

add_action( 'login_header', 'wpse330527_add_html_content' );
function wpse330527_add_html_content() {
?>

ENTER YOUR HTML CODE

<?php
}

You will add the code into functions.php file of your active theme.

1

Some notes

You may notice that the login_init hook puts the code immediately under the body tag, and the login_header code is inserted later. Other tags are described in the documentation, here:

  • Actions in the head of the document: login_enqueue_scripts, login_head.
  • Filters in the body: login_headerurl, login_headertitle, login_message, login_errors.
  • Actions at the bottom of and below the form: login_form, login_footer.

The Code:

// define the login_init callback 
function action_login_init( $array ) { ?>
  <h1 class='even-above-login_header'>hi</h1>
<?php }; 
       
// add the action 
add_action( 'login_init', 'action_login_init', 10, 1 );  

The Result:

<body>
  <h1 class="even-above-login_header">hi</h1>
  <!-- etc -->
</body>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.