0

I am trying to change the title which is shown in Tabs/Windows when visiting a page you have no access to, where it now says "WordPress > Error".

This is how far I have come, but it doesn't work at all:

add_filter( 'wp_die_handler', 'change_die_wpse_120304' );
function change_die_wpse_120304()
{
    return 'do_wp_die_wpse_120304';
}

function do_wp_die_wpse_120304( $message, $title, $args )
{
    return 'Mynewtitle'.' • '.$title.' ‹ '.get_bloginfo('name'); 
}

I think wp_die_handler has something to do with this, but I cannot find any solution for this.

2
  • 1
    Can you elaborate a bit? When you say "when visiting a page you have no access to" do you mean a non-existent web page that ought to 404? Or do you mean a part of the admin that you don't have permissions for? Commented Apr 5, 2018 at 15:48
  • A part of the admin you dont have permissions for. Sorry for not making it clear!
    – jockebq
    Commented Apr 5, 2018 at 16:14

1 Answer 1

0

The wp_die_handler filter filters the handler for the function responsible to kill the execution of the script. So it needs to return the callable that WordPress will use when wp_die() is called.

The actual callable that is returned from the wp_die_handler filter must output the error message and die.

function wpse_die( $message, $title = '', $args = [] ) {
  echo 'yolo';
  die;
}

function wpse_die_handler(){
  return 'wpse_die';
}
add_filter( 'wp_die_handler', 'wpse_die_handler' );

Have a look at _default_wp_die_handler() for a look at what WordPress outputs from the default handler for wp_die().

4
  • I tried inserting return 'Mynewtitle'.' • '.$title.' ‹ '.get_bloginfo('name'); where you put echo 'yolo'; but it doesn't work. I am not sure I understand what I am missing here.
    – jockebq
    Commented Apr 5, 2018 at 16:37
  • You want to echo and die, not return. Commented Apr 5, 2018 at 16:46
  • So this is my new code: echo 'Mynewtitle'.' • '.$title.' ‹ '.get_bloginfo('name'); die; Still not working!
    – jockebq
    Commented Apr 5, 2018 at 17:11
  • I have been trying everything for the last 2 hours without coming anywhere. How do I edit the title?
    – jockebq
    Commented Apr 9, 2018 at 9:33

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.