wp_admin_canonical_url

The timeline below displays how wordpress function wp_admin_canonical_url has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Removes single-use URL parameters and create canonical link based on new URL.
 *
 * Removes specific query string parameters from a URL, create the canonical link,
 * put it in the admin header, and change the current URL to match.
 *
 * @since 4.2.0
 */
function wp_admin_canonical_url()
{
    $removable_query_args = wp_removable_query_args();
    if (empty($removable_query_args)) {
        return;
    }
    // Ensure we're using an absolute URL.
    $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    $filtered_url = remove_query_arg($removable_query_args, $current_url);
    /**
     * Filters the admin canonical url value.
     *
     * @since 6.5.0
     *
     * @param string $filtered_url The admin canonical url value.
     */
    $filtered_url = apply_filters('wp_admin_canonical_url', $filtered_url);
    ?>
	<link id="wp-admin-canonical" rel="canonical" href="<?php 
    echo esc_url($filtered_url);
    ?>" />
	<script>
		if ( window.history.replaceState ) {
			window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
		}
	</script>
	<?php 
}

WordPress Version: 6.1

/**
 * Removes single-use URL parameters and create canonical link based on new URL.
 *
 * Removes specific query string parameters from a URL, create the canonical link,
 * put it in the admin header, and change the current URL to match.
 *
 * @since 4.2.0
 */
function wp_admin_canonical_url()
{
    $removable_query_args = wp_removable_query_args();
    if (empty($removable_query_args)) {
        return;
    }
    // Ensure we're using an absolute URL.
    $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    $filtered_url = remove_query_arg($removable_query_args, $current_url);
    ?>
	<link id="wp-admin-canonical" rel="canonical" href="<?php 
    echo esc_url($filtered_url);
    ?>" />
	<script>
		if ( window.history.replaceState ) {
			window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
		}
	</script>
	<?php 
}

WordPress Version: 5.1

/**
 * Remove single-use URL parameters and create canonical link based on new URL.
 *
 * Remove specific query string parameters from a URL, create the canonical link,
 * put it in the admin header, and change the current URL to match.
 *
 * @since 4.2.0
 */
function wp_admin_canonical_url()
{
    $removable_query_args = wp_removable_query_args();
    if (empty($removable_query_args)) {
        return;
    }
    // Ensure we're using an absolute URL.
    $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    $filtered_url = remove_query_arg($removable_query_args, $current_url);
    ?>
	<link id="wp-admin-canonical" rel="canonical" href="<?php 
    echo esc_url($filtered_url);
    ?>" />
	<script>
		if ( window.history.replaceState ) {
			window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
		}
	</script>
	<?php 
}

WordPress Version: 4.4

/**
 * Remove single-use URL parameters and create canonical link based on new URL.
 *
 * Remove specific query string parameters from a URL, create the canonical link,
 * put it in the admin header, and change the current URL to match.
 *
 * @since 4.2.0
 */
function wp_admin_canonical_url()
{
    $removable_query_args = wp_removable_query_args();
    if (empty($removable_query_args)) {
        return;
    }
    // Ensure we're using an absolute URL.
    $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    $filtered_url = remove_query_arg($removable_query_args, $current_url);
    ?>
	<link id="wp-admin-canonical" rel="canonical" href="<?php 
    echo esc_url($filtered_url);
    ?>" />
	<script>
		if ( window.history.replaceState ) {
			window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
		}
	</script>
<?php 
}

WordPress Version: 4.2

/**
 * Remove single-use URL parameters and create canonical link based on new URL.
 *
 * Remove specific query string parameters from a URL, create the canonical link,
 * put it in the admin header, and change the current URL to match.
 *
 * @since 4.2.0
 */
function wp_admin_canonical_url()
{
    $removable_query_args = array('message', 'settings-updated', 'saved', 'update', 'updated', 'activated', 'activate', 'deactivate', 'locked', 'deleted', 'trashed', 'untrashed', 'enabled', 'disabled', 'skipped', 'spammed', 'unspammed');
    /**
     * Filter the list of URL parameters to remove.
     *
     * @since 4.2.0
     *
     * @param array $removable_query_args An array of parameters to remove from the URL.
     */
    $removable_query_args = apply_filters('removable_query_args', $removable_query_args);
    if (empty($removable_query_args)) {
        return;
    }
    // Ensure we're using an absolute URL.
    $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    $filtered_url = remove_query_arg($removable_query_args, $current_url);
    ?>
	<link id="wp-admin-canonical" rel="canonical" href="<?php 
    echo esc_url($filtered_url);
    ?>" />
	<script>
		if ( window.history.replaceState ) {
			window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
		}
	</script>
<?php 
}