Using WordPress ‘post_form_autocomplete_off()’ PHP function

The post_form_autocomplete_off() WordPress PHP function disables autocomplete on the ‘post’ form (Add/Edit Post screens) for WebKit browsers, as they disregard the autocomplete setting on the editor textarea. This can break the editor when the user navigates to it with the browser’s Back button. See #28037.

Usage

post_form_autocomplete_off();

Parameters

  • None

More information

See WordPress Developer Resources: post_form_autocomplete_off()

This function has been replaced with wp_page_reload_on_back_button_js() that also fixes this problem.

Examples

Disable Autocomplete on Post Form

Disables autocomplete on the post form for WebKit browsers to avoid breaking the editor when navigating with the browser’s Back button.

add_action('admin_print_scripts', 'disable_autocomplete');

function disable_autocomplete() {
post_form_autocomplete_off();
}

Disable Autocomplete on Custom Post Type Form

Disables autocomplete on a custom post type form for WebKit browsers to prevent editor issues.

add_action('admin_print_scripts', 'disable_autocomplete_custom_post_type');

function disable_autocomplete_custom_post_type() {
global $post_type;

if ('custom_post_type' == $post_type) {
post_form_autocomplete_off();
}
}

Disable Autocomplete on Specific Post Form

Disables autocomplete on a specific post form for WebKit browsers to prevent editor issues.

add_action('admin_print_scripts', 'disable_autocomplete_specific_post');

function disable_autocomplete_specific_post() {
global $post;

if (123 == $post->ID) {
post_form_autocomplete_off();
}
}

Disable Autocomplete on Post Form with Conditional Logic

Disables autocomplete on the post form for WebKit browsers only when a specific condition is met.

add_action('admin_print_scripts', 'conditionally_disable_autocomplete');

function conditionally_disable_autocomplete() {
if (some_condition()) {
post_form_autocomplete_off();
}
}

function some_condition() {
// Your custom condition logic
return true;
}

Disable Autocomplete on All Edit Screens

Disables autocomplete on all edit screens for WebKit browsers to avoid breaking the editor.

add_action('admin_print_scripts', 'disable_autocomplete_all_edit_screens');

function disable_autocomplete_all_edit_screens() {
if (get_current_screen()->base == 'post') {
post_form_autocomplete_off();
}
}