| 33 | /** |
| 34 | * Remove specific query string parameters from a URL. |
| 35 | * |
| 36 | * @since 4.2.0 |
| 37 | * |
| 38 | * @return string The filtered URL with parameters stripped. |
| 39 | */ |
| 40 | function wp_admin_filtered_url() { |
| 41 | $removable_url_params = array( |
| 42 | 'message', 'updated', 'settings-updated', |
| 43 | 'saved', 'activated', 'activate', |
| 44 | 'deactivate', 'locked', 'skipped', |
| 45 | 'deleted', 'trashed', 'untrashed', |
| 46 | ); |
| 47 | |
| 48 | /** |
| 49 | * Filter the list of URL parameters to remove. |
| 50 | * |
| 51 | * @since 4.2.0 |
| 52 | * |
| 53 | * @param array $removable_url_params An array of parameters to remove from the URL. |
| 54 | */ |
| 55 | $removable_url_params = apply_filters( 'removable_url_params', $removable_url_params ); |
| 56 | |
| 57 | // Ensure we're using an absolute URL. |
| 58 | return get_site_url() . remove_query_arg( $removable_url_params ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Prints the filtered canonical link in the admin header and change the current URL to match. |
| 63 | * |
| 64 | * @since 4.2.0 |
| 65 | */ |
| 66 | function wp_admin_canonical_url_head() { |
| 67 | ?> |
| 68 | <link id="wp-admin-canonical" rel="canonical" href="<?php echo esc_url( wp_admin_filtered_url() ); ?>" /> |
| 69 | <script>if ( jQuery.isFunction( history.replaceState ) ) { |
| 70 | history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href ); |
| 71 | }</script> |
| 72 | <?php |
| 73 | } |
| 74 | |
| 75 | add_action( 'admin_head', 'wp_admin_canonical_url_head', 20 ); |
| 76 | |