0

I use the function below to manually trigger temporary 'maintenance mode'.

function maintenance_mode(){
if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ){
wp_die('<img src="/graphics/header/logo/1.png" />
<p><strong>Site temporarily offline for maintenance.</strong> </p>' );
}}
add_action( 'get_header', 'maintenance_mode' );

The page title displays as 'WordPress > error' - which I want to replace with a more appropriate alternative.

1

You can pass a title to the wp_die() function or even any other HTML content like heading tags:
https://codex.wordpress.org/Function_Reference/wp_die

But if you are trying to have more control over what's being outputted, you should use the template_include filter and use your custom template:
https://codex.wordpress.org/Plugin_API/Filter_Reference/template_include

EXAMPLE:

add_filter( 'template_include', 'show_maintenance_page', 99 );

function show_maintenance_page( $template ) {
    if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ){
        $new_template = locate_template( array( 'maintenance-template.php' ) );
        if ( !empty( $new_template ) ) {
            return $new_template;
        }
    }
    return $template;

}

Create a file called maintenance-template.php on the root theme folder for this example:

<?php
/*
Template Name: Maintenance mode
*/ 
?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/graphics/header/logo/1.png" />
<p>
    <strong>Site temporarily offline for maintenance.</strong> 
</p>
  • Thanks. Passing a title sorts the immediate issue - though I'm interested in your 'template_include' suggestion but having read the linked article still can't understand how to use it in this instance. – glvr May 29 '18 at 4:24
  • Hi @glvr I've updated my answer with an example, please take a look now – Pabamato May 29 '18 at 21:16
  • Ah, thanks... I see. (And I'm sorry for my slow reply.) – glvr Jun 4 '18 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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