WordPress Help Articles

WordPress Folders Database Sizes

WordPress Folder Size and Database Optimization Guide

Updated: February 25, 2025

Managing disk space is crucial for maintaining a fast and efficient WordPress website. Over time, websites accumulate large amounts of data, including media files, plugins, and database records, which can slow down performance. Monitoring and optimizing your WordPress folder size and database can prevent unnecessary storage bloat and enhance your site’s speed and functionality.

In this guide, we’ll explore how to check your WordPress storage usage and database size, manually optimize your site, and use tools like the WordPress Folders & Database Sizes plugin for easier management.

Why You Should Monitor WordPress Folder Size and Database Usage

A growing website means increasing file sizes, additional plugin installations, and expanding database records. Without proper monitoring, your website can experience:

  • Slower Page Load Speeds – Large files and bloated databases take longer to process.
  • Higher Hosting Costs – Many hosting plans charge based on storage usage.
  • Backup and Restore Issues – Larger websites take longer to back up and restore.
  • Security Risks – Old, unused files and database entries can become vulnerabilities.

Understanding how to measure and optimize your WordPress storage is essential for maintaining a high-performing website.

How to Check WordPress Folder Size & Database Usage

The WordPress Folders & Database Sizes plugin is an easy way to analyze your website’s storage. Here’s how to use it:

  1. Install the Plugin: Download it here and install it in your WordPress dashboard.
  2. Activate the Plugin: Navigate to Plugins > Add New > Upload Plugin, then activate it.
  3. View the Size Report: After activation, find the WP Size menu in your dashboard. This tool provides a breakdown of folder sizes and database usage.

With this plugin, you can quickly see which areas of your site consume the most space and take necessary actions.
Screenshot 20240501 225951

How to Optimize WordPress Folder Size and Database

  1. Delete Unused Plugins and Themes
    • Navigate to Appearance > Themes and delete inactive themes.
    • Go to Plugins > Installed Plugins, deactivate and remove any unused plugins.
  2. Optimize the Media Library
    • Use a tool like Imagify to compress images.
    • Delete unused media files from Media > Library.
  3. Clean Up the Database
    • Use a plugin like WP-Optimize to remove:
      • Post revisions
      • Spam comments
      • Transient options
      • Expired cache
  4. Implement a Caching Solution
    • Use caching plugins like WP Rocket or W3 Total Cache to reduce database queries and optimize performance.

Automate Folder Size & Database Monitoring with Code

If you want to integrate automatic WordPress folder size and database monitoring directly into your admin panel, you can use the following PHP code in your theme’s functions.php file:

function viawebs_get_database_size() {
    global $wpdb;
    $sql = "SELECT SUM(data_length + index_length) AS size FROM information_schema.tables WHERE table_schema = '" . DB_NAME . "'";
    $size = $wpdb->get_var($sql);
    return $size;
}

function viawebs_calculate_directory_sizes() {
    $document_root = $_SERVER['DOCUMENT_ROOT']; 

    function viawebs_directory_size($dir) {
        $size = 0;
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS)) as $file) {
            $size += $file->getSize();
        }
        return $size;
    }

    function viawebs_size_to_mb($size) {
        return number_format($size / 1024 / 1024, 2);
    }

    $total_size = 0;
    $output = '<tr><td><strong>Folder</strong></td><td><strong>Size</strong></td></tr>';

    foreach (new DirectoryIterator($document_root) as $folder) {
        if ($folder->isDot() || !$folder->isDir()) continue;
        
        $folder_path = $folder->getRealPath();
        $folder_size = viawebs_directory_size($folder_path);
        $total_size += $folder_size;
        $output .= '<tr><td>' . $folder->getFilename() . '</td><td>' . viawebs_size_to_mb($folder_size) . ' MB</td></tr>';

        if ($folder->getFilename() === 'wp-content') {
            foreach (new DirectoryIterator($folder_path) as $subfolder) {
                if ($subfolder->isDot() || !$subfolder->isDir()) continue;
                
                $subfolder_size = viawebs_directory_size($subfolder->getRealPath());
                $output .= '<tr><td>    ' . $subfolder->getFilename() . '</td><td>' . viawebs_size_to_mb($subfolder_size) . ' MB</td></tr>';
            }
        }
    }

    $db_size = viawebs_get_database_size();
    $total_size += $db_size;
    $output .= '<tr><td>Database</td><td>' . viawebs_size_to_mb($db_size) . ' MB</td></tr>';

    $total_size_gb = number_format($total_size / 1024 / 1024 / 1024, 2);

    $output .= "<tr><td><strong>Total Size of Files and Database:</strong></td><td><strong>" . $total_size_gb . " GB</strong></td></tr>";

    return $output;
}

function viawebs_add_directory_sizes_admin_page() {
    add_menu_page(
        'WordPress Folders & Database Sizes',
        'WP Size',
        'manage_options',
        'wp-size',
        'directory_sizes_page_html'
    );
}

function directory_sizes_page_html() {
    if (!current_user_can('manage_options')) {
        return;
    }

    echo '<div class="wrap">';
    echo '<h1>' . esc_html(get_admin_page_title()) . '</h1>';
    echo '<table>';
    echo viawebs_calculate_directory_sizes();
    echo '</table>';
    echo '</div>';
}
add_action('admin_menu', 'viawebs_add_directory_sizes_admin_page');

This code calculates total folder and database size and adds a report section in the WordPress admin panel under “WP Size”.

Optimizing your WordPress folder size and database is essential for maintaining a fast and secure website. Regularly monitoring storage usage, cleaning unnecessary files, and using the right tools can help prevent performance issues. Whether you use a plugin like WordPress Folders & Database Sizes or opt for manual optimization, staying proactive ensures your website remains efficient and scalable.

 

Via Webs Offers WordPress Hosting & Maintenance Services For Those That Prefer To Focus On Something Other Than The Technical Aspects

Our rollover development time lets you save unused hours for future assistance. Stay updated and optimized, with the flexibility to invest in new functionality.

Article Categories

Dive in to something specific you are wanting to learn more about.

Let's Get Started!