Using WordPress ‘is_archived()’ PHP function

The is_archived() WordPress PHP function checks if a particular blog is archived.

Usage

$result = is_archived( $id );

For example, if $id is 3, the function will check if blog with ID 3 is archived, and return true if it is, or false if it is not.

Parameters

  • $id (int) – Required. The ID of the blog to check if it is archived.

More information

See WordPress Developer Resources: is_archived()

Examples

Check if the current blog is archived

Check if the current blog is archived and display a message if it is.

if (is_archived(get_current_blog_id())) {
    echo "This blog is archived.";
} else {
    echo "This blog is active.";
}

Show archived blogs from an array of blog IDs

Display the blog titles of archived blogs from a given array of blog IDs.

$blog_ids = array(1, 2, 3, 4, 5);

foreach ($blog_ids as $blog_id) {
    if (is_archived($blog_id)) {
        echo get_bloginfo('name', $blog_id) . " is archived.<br />";
    }
}

Filter an array of blogs to only show archived ones

Filter an array of blog IDs to return only those that are archived.

$blog_ids = array(1, 2, 3, 4, 5);
$archived_blogs = array_filter($blog_ids, 'is_archived');

Check if a blog is archived based on its URL

Check if a blog is archived using its URL.

$url = "https://example.com/blog";
$blog_id = url_to_blogid($url);

if (is_archived($blog_id)) {
    echo "The blog at $url is archived.";
} else {
    echo "The blog at $url is active.";
}

Display a custom message for archived blogs

Display a custom message for archived blogs when a user visits the blog.

function display_archived_message() {
    if (is_archived(get_current_blog_id())) {
        echo '<div class="archived-message">This blog is archived and no longer updated.</div>';
    }
}
add_action('wp_footer', 'display_archived_message');