skip to Main Content

When I update my WordPress site; The site will be temporarily unavailable to users and a text will be displayed stating that the site has been updated.

I am looking for a code so that I can change the display text and also display an image to the user.

I don’t know any code or solution for this issue and I searched for such code but didn’t find anything.

I need any kind of help or guidance.

Thank you in advance.

2

Answers


  1. Is there any type of video/screenshot you can show in order to further help you?

    Login or Signup to reply.
  2. Make sure to replace ‘https://example.com/path/to/your/image.jpg’ with the URL of the image you want to display, and ‘The site is currently undergoing maintenance. Please check back soon.’ with your custom maintenance mode message.

    After adding this code to your theme’s functions.php file, save the file, and the custom maintenance mode page will be displayed to non-admin users whenever the site is being updated. Admin users, who have the capability to edit themes, will still be able to access the site normally.

    Remember to remove or comment out this code once you no longer need the maintenance mode functionality to allow regular access to your site.

     function custom_maintenance_mode_page() {
            if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
                // Display the custom maintenance mode page for non-admin users
                $image_url = 'https://example.com/path/to/your/image.jpg'; // Replace with your image URL
                $text = 'The site is currently undergoing maintenance. Please check back soon.'; // Replace with your custom text
        
                // Output the HTML for the maintenance mode page
                echo '<html>';
                echo '<body>';
                echo '<div style="text-align:center;margin-top:100px;">';
                echo '<img src="' . esc_url( $image_url ) . '" alt="Maintenance Image" style="max-width: 400px;height: auto;" />';
                echo '<p>' . esc_html( $text ) . '</p>';
                echo '</div>';
                echo '</body>';
                echo '</html>';
                die(); // Stop further execution of the script
            }
        }
        add_action( 'get_header', 'custom_maintenance_mode_page' );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search