Halloween Sale 15% off Ends in See the plans
PHP

Login Page Background Image

Covers the login page with a full-screen background photo and a dark overlay that keeps the form readable.

Don’t have WPIDE yet? Install it on your site

Code

// Full URL of the background image, and the overlay color on top of it.
$wpide_login_bg_image   = 'https://example.com/wp-content/uploads/login-background.jpg';
$wpide_login_bg_overlay = 'rgba(0, 0, 0, 0.35)';

add_action( 'login_enqueue_scripts', function () use ( $wpide_login_bg_image, $wpide_login_bg_overlay ) {
    $image   = esc_url_raw( $wpide_login_bg_image );
    $overlay = preg_replace( '/[^a-zA-Z0-9#(),.\s%]/', '', $wpide_login_bg_overlay );

    if ( ! $image ) {
        return;
    }

    wp_add_inline_style( 'login', sprintf(
        'body.login{background:linear-gradient(%1$s,%1$s),url("%2$s") center / cover no-repeat fixed;}' .
        '.login #backtoblog a,.login #nav a,.login .privacy-policy-page-link a{color:#fff;text-shadow:0 1px 2px rgba(0,0,0,.6);}',
        $overlay,
        $image
    ) );
} );

Notes

Use a compressed image of about 1920px wide so the login page stays fast.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.