The label_remember
argument is for changing the text only; HTML will be escaped, so that won’t work here.
Instead, the HTML for the login form can be parsed and modified before it is output:
// Get the HTML for the login form
$login_form = wp_login_form( [ 'echo' => false ] );
// Create an instance of DOMDocument
$dom = new \DOMDocument();
// Populate $dom with our login form, making sure to handle UTF-8, otherwise
// problems will occur with UTF-8 characters.
$dom->loadHTML( mb_convert_encoding( $login_form, 'HTML-ENTITIES', 'UTF-8' ) );
// Create an instance of DOMXpath and get the <p class="login-remember"> node
$xpath = new \DOMXpath( $dom );
$remember = $xpath->query( '//p[@class="login-remember"]' );
// Iterate over the $remember node...
foreach ( $remember as $container ) {
// Create the <span> element
$checkbox_span = $dom->createElement( 'span' );
// Create the class attribute
$checkbox_span_attr = $dom->createAttribute( 'class' );
// Set the value of the class attribute
$checkbox_span_attr->value="custom-styled-checkbox";
// Add class="custom-styled-checkbox" to the <span> element
$checkbox_span->appendChild( $checkbox_span_attr );
// Append the completed <span class="custom-styled-checkbox"></span> element
// to <p class="login-remember"><label>
//$container->childNodes[0]->appendChild( $checkbox_span ); // Fails on PHP < 5.6.3?
$container->childNodes->item(0)->appendChild( $checkbox_span );
}
// Save the updated HTML to $login_form and output it.
$login_form = $dom->saveHTML();
echo $login_form;