845 | | add_action( 'post_edit_form_tag', 'post_form_autocomplete_off' ); |
| 846 | /** |
| 847 | * Remove single-use URL parameters and create canonical link based on new URL. |
| 848 | * |
| 849 | * Remove specific query string parameters from a URL, create the canonical link, |
| 850 | * put it in the admin header, and change the current URL to match. |
| 851 | * |
| 852 | * @since 4.2.0 |
| 853 | */ |
| 854 | function wp_admin_canonical_url() { |
| 855 | $removable_query_args = array( |
| 856 | 'message', 'settings-updated', 'saved', |
| 857 | 'update', 'updated','activated', |
| 858 | 'activate', 'deactivate', 'locked', |
| 859 | 'deleted', 'trashed', 'untrashed', |
| 860 | 'enabled', 'disabled', 'skipped', |
| 861 | ); |
| 862 | |
| 863 | /** |
| 864 | * Filter the list of URL parameters to remove. |
| 865 | * |
| 866 | * @since 4.2.0 |
| 867 | * |
| 868 | * @param array $removable_query_args An array of parameters to remove from the URL. |
| 869 | */ |
| 870 | $removable_query_args = apply_filters( 'removable_query_args', $removable_query_args ); |
| 871 | |
| 872 | if ( empty( $removable_query_args ) ) { |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | // Ensure we're using an absolute URL. |
| 877 | $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
| 878 | $filtered_url = remove_query_arg( $removable_query_args, $current_url ); |
| 879 | ?> |
| 880 | <link id="wp-admin-canonical" rel="canonical" href="<?php echo esc_url( $filtered_url ); ?>" /> |
| 881 | <script> |
| 882 | if ( window.history.replaceState ) { |
| 883 | window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href ); |
| 884 | } |
| 885 | </script> |
| 886 | <?php |
| 887 | } |
| 888 | add_action( 'admin_head', 'wp_admin_canonical_url' ); |