Using WordPress ‘block_editor_no_javascript_message’ PHP filter

The block_editor_no_javascript_message WordPress PHP filter allows you to modify the message displayed in the block editor interface when JavaScript is not enabled in the browser.

Usage

add_filter('block_editor_no_javascript_message', 'your_custom_function', 10, 2);

function your_custom_function($message, $post) {
    // your custom code here
    return $message;
}

Parameters

  • $message (string): The message being displayed.
  • $post (WP_Post): The post being edited.

More information

See WordPress Developer Resources: block_editor_no_javascript_message

Examples

Change the default message

Customize the message displayed when JavaScript is disabled.

add_filter('block_editor_no_javascript_message', 'change_no_js_message', 10, 2);

function change_no_js_message($message, $post) {
    $message = 'Please enable JavaScript in your browser to use the block editor.';
    return $message;
}

Display a different message for a specific post type

Show a custom message for a particular post type when JavaScript is disabled.

add_filter('block_editor_no_javascript_message', 'custom_post_type_no_js_message', 10, 2);

function custom_post_type_no_js_message($message, $post) {
    if ($post->post_type === 'custom_post_type') {
        $message = 'Please enable JavaScript to edit this custom post type.';
    }
    return $message;
}

Add an admin email address to the message

Include the admin email in the message to contact for help.

add_filter('block_editor_no_javascript_message', 'add_admin_email_to_message', 10, 2);

function add_admin_email_to_message($message, $post) {
    $admin_email = get_option('admin_email');
    $message .= ' For assistance, please contact: ' . $admin_email;
    return $message;
}

Display a different message based on user role

Show a custom message depending on the user role when JavaScript is disabled.

add_filter('block_editor_no_javascript_message', 'user_role_no_js_message', 10, 2);

function user_role_no_js_message($message, $post) {
    $user = wp_get_current_user();
    if (in_array('editor', $user->roles)) {
        $message = 'Dear Editor, please enable JavaScript in your browser to use the block editor.';
    }
    return $message;
}

Include a link to a help page for users to learn how to enable JavaScript.

add_filter('block_editor_no_javascript_message', 'add_help_link_to_message', 10, 2);

function add_help_link_to_message($message, $post) {
    $help_link = 'https://www.example.com/enable-javascript/';
    $message .= ' For help on enabling JavaScript, visit: ' . $help_link;
    return $message;
}