<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>wordpress speed Archives - WP-CLI Mastery</title>
	<atom:link href="https://wpclimastery.com/blog/tag/wordpress-speed/feed/" rel="self" type="application/rss+xml" />
	<link>https://wpclimastery.com/blog/tag/wordpress-speed/</link>
	<description>Automate WordPress Like a DevOps Pro.</description>
	<lastBuildDate>Mon, 24 Nov 2025 11:16:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wpclimastery.com/wp-content/uploads/2025/11/cropped-favicon-32x32.webp</url>
	<title>wordpress speed Archives - WP-CLI Mastery</title>
	<link>https://wpclimastery.com/blog/tag/wordpress-speed/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Optimize WordPress Performance with WP-CLI: 15 Proven Techniques</title>
		<link>https://wpclimastery.com/blog/optimize-wordpress-performance-with-wp-cli-15-proven-techniques/</link>
					<comments>https://wpclimastery.com/blog/optimize-wordpress-performance-with-wp-cli-15-proven-techniques/#respond</comments>
		
		<dc:creator><![CDATA[Krasen]]></dc:creator>
		<pubDate>Mon, 24 Nov 2025 11:16:24 +0000</pubDate>
				<category><![CDATA[Advanced WP-CLI Techniques]]></category>
		<category><![CDATA[database optimization wpcli]]></category>
		<category><![CDATA[optimize wordpress cli]]></category>
		<category><![CDATA[wordpress performance]]></category>
		<category><![CDATA[wordpress speed]]></category>
		<category><![CDATA[wp-cli optimization]]></category>
		<guid isPermaLink="false">https://wpclimastery.com/?p=223</guid>

					<description><![CDATA[<p>Website performance directly impacts user experience, search engine rankings, and conversion rates. WP-CLI provides powerful tools to diagnose performance bottlenecks and implement optimizations efficiently, making it essential for developers managing...</p>
<p>The post <a href="https://wpclimastery.com/blog/optimize-wordpress-performance-with-wp-cli-15-proven-techniques/">Optimize WordPress Performance with WP-CLI: 15 Proven Techniques</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Website performance directly impacts user experience, search engine rankings, and conversion rates. WP-CLI provides powerful tools to diagnose performance bottlenecks and implement optimizations efficiently, making it essential for developers managing high-traffic WordPress sites.</p>



<h2 class="wp-block-heading" id="why-use-wp-cli-for-performance-optimization">Why Use WP-CLI for Performance Optimization</h2>



<p>Traditional WordPress performance optimization through the dashboard is time-consuming and often incomplete. WP-CLI enables systematic, repeatable optimizations that can be automated, scripted, and applied across multiple sites simultaneously.</p>



<p>The command-line approach offers distinct advantages: batch processing of operations, precise control over optimization tasks, ability to schedule regular maintenance, detailed logging of changes, and integration with deployment pipelines. These capabilities make WP-CLI indispensable for professional WordPress performance management.</p>



<h2 class="wp-block-heading" id="1-database-optimization-and-cleanup">1. Database Optimization and Cleanup</h2>



<p>Database bloat significantly impacts query performance. Over time, WordPress databases accumulate revisions, spam comments, orphaned metadata, and expired transients that slow down queries.</p>



<pre class="wp-block-code"><code><em># Check database size before optimization</em>
wp db size --tables

<em># Optimize all database tables</em>
wp db optimize

<em># Remove post revisions older than 30 days</em>
wp post delete $(wp post list --post_type=revision --format=ids --date_query='&#91;{"before":"30 days ago"}]') --force

<em># Clean up spam and trashed comments</em>
wp comment delete $(wp comment list --status=spam --format=ids) --force
wp comment delete $(wp comment list --status=trash --format=ids) --force

<em># Remove orphaned post metadata</em>
wp db query "DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL"

<em># Clean expired transients</em>
wp transient delete --expired

<em># Remove all transients (use cautiously)</em>
wp transient delete --all
</code></pre>



<p>Create a comprehensive database cleanup script:</p>



<pre class="wp-block-code"><code>#!/bin/bash
<em># db-cleanup.sh - Comprehensive database optimization</em>

WP_PATH="/var/www/html"

echo "Starting database optimization..."

<em># Backup before cleanup</em>
wp --path="$WP_PATH" db export backup-pre-cleanup-$(date +%Y%m%d).sql

<em># Get initial database size</em>
INITIAL_SIZE=$(wp --path="$WP_PATH" db size --human-readable --format=json | jq -r '.Size')
echo "Initial database size: $INITIAL_SIZE"

<em># Remove old post revisions (keep last 5 for each post)</em>
wp --path="$WP_PATH" config set WP_POST_REVISIONS 5 --type=constant

<em># Delete old auto-drafts</em>
wp --path="$WP_PATH" post delete $(wp --path="$WP_PATH" post list --post_status=auto-draft --format=ids) --force

<em># Clean comments</em>
wp --path="$WP_PATH" comment delete $(wp --path="$WP_PATH" comment list --status=spam --format=ids) --force
wp --path="$WP_PATH" comment delete $(wp --path="$WP_PATH" comment list --status=trash --format=ids) --force

<em># Remove orphaned metadata</em>
wp --path="$WP_PATH" db query "DELETE FROM wp_commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM wp_comments)"
wp --path="$WP_PATH" db query "DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT ID FROM wp_posts)"
wp --path="$WP_PATH" db query "DELETE FROM wp_termmeta WHERE term_id NOT IN (SELECT term_id FROM wp_terms)"

<em># Clean transients</em>
wp --path="$WP_PATH" transient delete --expired

<em># Optimize tables</em>
wp --path="$WP_PATH" db optimize

<em># Get final database size</em>
FINAL_SIZE=$(wp --path="$WP_PATH" db size --human-readable --format=json | jq -r '.Size')
echo "Final database size: $FINAL_SIZE"
echo "Database optimization completed"
</code></pre>



<h2 class="wp-block-heading" id="2-cache-management">2. Cache Management</h2>



<p>Effective cache management is crucial for performance. WP-CLI provides commands to manage object cache, page cache, and opcode cache.</p>



<pre class="wp-block-code"><code><em># Flush object cache (Redis, Memcached, etc.)</em>
wp cache flush

<em># Test cache functionality</em>
wp cache set test_key test_value 300
wp cache get test_key

<em># For sites using Redis</em>
wp redis info

<em># Clear page cache for specific plugins</em>
<em># W3 Total Cache</em>
wp w3-total-cache flush all

<em># WP Super Cache</em>
wp cache flush

<em># Clear cache for specific pages/posts</em>
wp transient delete --all
</code></pre>



<p>Implement intelligent cache warming:</p>



<pre class="wp-block-code"><code>#!/bin/bash
<em># cache-warm.sh - Warm up cache for important pages</em>

SITE_URL="https://example.com"
WP_PATH="/var/www/html"

<em># Get list of published posts and pages</em>
URLS=$(wp --path="$WP_PATH" post list --post_type=post,page --post_status=publish --field=url)

<em># Warm cache by requesting each URL</em>
for url in $URLS; do
    echo "Warming cache: $url"
    curl -s -o /dev/null "$url"
    sleep 0.5  <em># Avoid overwhelming server</em>
done

<em># Warm up homepage and key pages</em>
curl -s -o /dev/null "$SITE_URL"
curl -s -o /dev/null "$SITE_URL/about"
curl -s -o /dev/null "$SITE_URL/contact"

echo "Cache warming completed"
</code></pre>



<h2 class="wp-block-heading" id="3-image-optimization">3. Image Optimization</h2>



<p>Images often account for the majority of page weight. WP-CLI can help automate image optimization tasks.</p>



<pre class="wp-block-code"><code><em># Regenerate thumbnails for all images</em>
wp media regenerate --yes

<em># Regenerate only missing thumbnails</em>
wp media regenerate --only-missing --yes

<em># Regenerate images uploaded in specific timeframe</em>
wp media regenerate --yes $(wp post list --post_type=attachment --format=ids --post_mime_type=image --year=2024)

<em># Install and configure image optimization plugin via CLI</em>
wp plugin install ewww-image-optimizer --activate
wp option update ewww_image_optimizer_cloud_key 'YOUR_API_KEY'

<em># Bulk optimize existing images</em>
wp ewwwio optimize all
</code></pre>



<h2 class="wp-block-heading" id="4-plugin-performance-audit">4. Plugin Performance Audit</h2>



<p>Identify and manage plugins that impact performance negatively.</p>



<pre class="wp-block-code"><code><em># List all active plugins</em>
wp plugin list --status=active

<em># Check for plugin updates</em>
wp plugin list --update=available

<em># Deactivate unused plugins</em>
wp plugin deactivate plugin-slug

<em># Remove unused plugins completely</em>
wp plugin delete plugin-slug

<em># Identify plugins loading on every page</em>
wp plugin list --status=active --field=name | while read plugin; do
    echo "Checking: $plugin"
    wp plugin path $plugin
done
</code></pre>



<p>Create a plugin performance audit script:</p>



<pre class="wp-block-code"><code>#!/bin/bash
<em># plugin-audit.sh - Audit plugin performance impact</em>

WP_PATH="/var/www/html"

echo "=== Plugin Performance Audit ==="

<em># List active plugins with version info</em>
echo -e "\nActive Plugins:"
wp --path="$WP_PATH" plugin list --status=active --fields=name,version,update,auto_update

<em># Check for outdated plugins</em>
echo -e "\nPlugins requiring updates:"
wp --path="$WP_PATH" plugin list --update=available --fields=name,version,update_version

<em># Identify plugins with known performance issues</em>
echo -e "\nChecking for resource-intensive plugins..."

<em># Get plugin file sizes</em>
for plugin in $(wp --path="$WP_PATH" plugin list --status=active --field=name); do
    PLUGIN_PATH=$(wp --path="$WP_PATH" plugin path $plugin)
    SIZE=$(du -sh "$PLUGIN_PATH" 2&gt;/dev/null | cut -f1)
    echo "$plugin: $SIZE"
done | sort -h
</code></pre>



<h2 class="wp-block-heading" id="5-autoload-optimization">5. Autoload Optimization</h2>



<p>Excessive autoloaded options slow down every WordPress request. Optimize autoloaded data to reduce overhead.</p>



<pre class="wp-block-code"><code><em># Check autoload size</em>
wp db query "SELECT SUM(LENGTH(option_value)) as autoload_size FROM wp_options WHERE autoload='yes'"

<em># List large autoloaded options</em>
wp db query "SELECT option_name, LENGTH(option_value) as size FROM wp_options WHERE autoload='yes' ORDER BY size DESC LIMIT 20"

<em># Convert large options to non-autoload</em>
wp option update large_option_name 'value' --autoload=no

<em># Remove obsolete autoloaded options</em>
wp db query "DELETE FROM wp_options WHERE autoload='yes' AND option_name LIKE '%_transient_%'"
</code></pre>



<h2 class="wp-block-heading" id="6-query-monitoring-and-optimization">6. Query Monitoring and Optimization</h2>



<p>Monitor database queries to identify performance bottlenecks.</p>



<pre class="wp-block-code"><code><em># Enable query logging (for development)</em>
wp config set SAVEQUERIES true --raw

<em># Check for slow queries in production</em>
wp db query "SELECT * FROM information_schema.processlist WHERE command != 'Sleep' AND time &gt; 5"

<em># Add database indexes for custom queries</em>
wp db query "CREATE INDEX idx_meta_key_value ON wp_postmeta(meta_key, meta_value(100))"

<em># Analyze table structure</em>
wp db query "SHOW INDEX FROM wp_posts"
wp db query "SHOW INDEX FROM wp_postmeta"
</code></pre>



<h2 class="wp-block-heading" id="7-content-delivery-network-integration">7. Content Delivery Network Integration</h2>



<p>Configure CDN settings programmatically for consistent deployment.</p>



<pre class="wp-block-code"><code><em># Update site URL for CDN</em>
wp search-replace 'https://example.com/wp-content' 'https://cdn.example.com/wp-content' --dry-run

<em># After verifying, perform the replacement</em>
wp search-replace 'https://example.com/wp-content' 'https://cdn.example.com/wp-content'

<em># Configure CDN plugin settings</em>
wp option update cdn_url 'https://cdn.example.com'
wp option update cdn_enabled 1
</code></pre>



<h2 class="wp-block-heading" id="8-lazy-loading-implementation">8. Lazy Loading Implementation</h2>



<p>Enable lazy loading for images and iframes to improve initial page load times.</p>



<pre class="wp-block-code"><code><em># WordPress native lazy loading (5.5+)</em>
wp option update wp_lazy_loading_enabled 1

<em># For older versions, use plugin</em>
wp plugin install lazy-load --activate

<em># Configure lazy loading settings</em>
wp option update lazy_load_images 1
wp option update lazy_load_iframes 1
</code></pre>



<h2 class="wp-block-heading" id="9-remove-unused-css-and-javascript">9. Remove Unused CSS and JavaScript</h2>



<p>Minimize loaded assets by disabling unnecessary scripts and styles.</p>



<pre class="wp-block-code"><code><em># Identify loaded scripts on homepage</em>
wp eval 'global $wp_scripts; print_r($wp_scripts-&gt;registered);'

<em># Dequeue unnecessary scripts via custom plugin</em>
cat &gt; wp-content/mu-plugins/performance-tweaks.php &lt;&lt; 'EOF'
&lt;?php
add_action('wp_enqueue_scripts', function() {
    // Remove jQuery migrate
    wp_deregister_script('jquery-migrate');

    // Remove emojis
    remove_action('wp_head', 'print_emoji_detection_script', 7);
    remove_action('wp_print_styles', 'print_emoji_styles');

    // Remove block library CSS if not using Gutenberg
    wp_dequeue_style('wp-block-library');
}, 100);
EOF
</code></pre>



<h2 class="wp-block-heading" id="10-php-opcode-cache-configuration">10. PHP Opcode Cache Configuration</h2>



<p>Ensure opcode cache is properly configured for optimal PHP performance.</p>



<pre class="wp-block-code"><code><em># Check if OPcache is enabled</em>
wp eval 'var_dump(function_exists("opcache_get_status"));'

<em># Get OPcache statistics</em>
wp eval 'print_r(opcache_get_status());'

<em># Clear OPcache when deploying code</em>
wp eval 'opcache_reset();'

<em># Check PHP version and loaded extensions</em>
wp cli info
</code></pre>



<h2 class="wp-block-heading" id="11-heartbeat-api-optimization">11. Heartbeat API Optimization</h2>



<p>The WordPress Heartbeat API can consume significant resources. Control its behavior to reduce server load.</p>



<pre class="wp-block-code"><code><em># Disable Heartbeat API completely</em>
cat &gt; wp-content/mu-plugins/disable-heartbeat.php &lt;&lt; 'EOF'
&lt;?php
add_action('init', function() {
    wp_deregister_script('heartbeat');
}, 1);
EOF

<em># Or modify Heartbeat interval</em>
cat &gt; wp-content/mu-plugins/modify-heartbeat.php &lt;&lt; 'EOF'
&lt;?php
add_filter('heartbeat_settings', function($settings) {
    $settings&#91;'interval'] = 60; // 60 seconds instead of 15
    return $settings;
});
EOF
</code></pre>



<h2 class="wp-block-heading" id="12-rest-api-performance">12. REST API Performance</h2>



<p>Optimize REST API endpoints to reduce unnecessary overhead.</p>



<pre class="wp-block-code"><code><em># Disable REST API for non-authenticated users</em>
cat &gt; wp-content/mu-plugins/restrict-rest-api.php &lt;&lt; 'EOF'
&lt;?php
add_filter('rest_authentication_errors', function($result) {
    if (!empty($result)) {
        return $result;
    }
    if (!is_user_logged_in()) {
        return new WP_Error(
            'rest_not_logged_in',
            'You are not logged in.',
            array('status' =&gt; 401)
        );
    }
    return $result;
});
EOF
</code></pre>



<h2 class="wp-block-heading" id="13-cron-optimization">13. Cron Optimization</h2>



<p>WordPress cron can impact performance during peak traffic. Disable WP-Cron and use system cron instead.</p>



<pre class="wp-block-code"><code><em># Disable WordPress cron</em>
wp config set DISABLE_WP_CRON true --raw

<em># Add system cron job to handle WP cron</em>
echo "*/15 * * * * wp --path=/var/www/html cron event run --due-now" | crontab -

<em># List scheduled cron events</em>
wp cron event list

<em># Test cron execution</em>
wp cron test
</code></pre>



<h2 class="wp-block-heading" id="14-asset-minification-and-concatenation">14. Asset Minification and Concatenation</h2>



<p>Reduce HTTP requests and file sizes through minification.</p>



<pre class="wp-block-code"><code><em># Install asset optimization plugin</em>
wp plugin install autoptimize --activate

<em># Configure via CLI</em>
wp option update autoptimize_html_optimize 1
wp option update autoptimize_js_optimize 1
wp option update autoptimize_css_optimize 1

<em># Clear optimization cache</em>
wp autoptimize cache clear
</code></pre>



<h2 class="wp-block-heading" id="15-performance-monitoring-and-benchmarking">15. Performance Monitoring and Benchmarking</h2>



<p>Establish baseline metrics and monitor performance over time.</p>



<pre class="wp-block-code"><code>#!/bin/bash
<em># performance-benchmark.sh - Monitor site performance</em>

WP_PATH="/var/www/html"
SITE_URL="https://example.com"

echo "=== WordPress Performance Benchmark ==="
echo "Date: $(date)"

<em># Database size</em>
echo -e "\nDatabase Size:"
wp --path="$WP_PATH" db size --human-readable

<em># Autoload size</em>
echo -e "\nAutoload Data:"
wp --path="$WP_PATH" db query "SELECT CONCAT(ROUND(SUM(LENGTH(option_value))/1024/1024,2),'MB') as autoload_size FROM wp_options WHERE autoload='yes'"

<em># Post counts</em>
echo -e "\nContent Statistics:"
wp --path="$WP_PATH" post list --post_type=post --format=count --post_status=publish | xargs -I {} echo "Published Posts: {}"
wp --path="$WP_PATH" post list --post_type=page --format=count --post_status=publish | xargs -I {} echo "Published Pages: {}"

<em># Plugin count</em>
echo -e "\nActive Plugins:"
wp --path="$WP_PATH" plugin list --status=active --format=count

<em># Theme check</em>
echo -e "\nActive Theme:"
wp --path="$WP_PATH" theme list --status=active --field=name

<em># Response time test</em>
echo -e "\nResponse Time:"
time curl -s -o /dev/null -w "Total: %{time_total}s\n" "$SITE_URL"

<em># Check for updates</em>
echo -e "\nAvailable Updates:"
wp --path="$WP_PATH" core check-update
wp --path="$WP_PATH" plugin list --update=available --format=count | xargs -I {} echo "Plugins: {}"
wp --path="$WP_PATH" theme list --update=available --format=count | xargs -I {} echo "Themes: {}"
</code></pre>



<h2 class="wp-block-heading" id="automated-performance-optimization">Automated Performance Optimization</h2>



<p>Combine techniques into a comprehensive automation script:</p>



<pre class="wp-block-code"><code>#!/bin/bash
<em># performance-optimize.sh - Complete performance optimization</em>

set -euo pipefail

WP_PATH="/var/www/html"
LOG_FILE="/var/log/wp-performance-$(date +%Y%m%d).log"

log() {
    echo "&#91;$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}

log "Starting performance optimization"

<em># Backup first</em>
log "Creating backup"
wp --path="$WP_PATH" db export "backup-$(date +%Y%m%d-%H%M%S).sql"

<em># Database optimization</em>
log "Optimizing database"
wp --path="$WP_PATH" db optimize
wp --path="$WP_PATH" transient delete --expired

<em># Clear caches</em>
log "Clearing caches"
wp --path="$WP_PATH" cache flush

<em># Update everything</em>
log "Checking for updates"
wp --path="$WP_PATH" core update --minor
wp --path="$WP_PATH" plugin update --all --exclude=custom-plugin
wp --path="$WP_PATH" theme update --all

<em># Regenerate missing thumbnails</em>
log "Regenerating missing thumbnails"
wp --path="$WP_PATH" media regenerate --only-missing --yes

<em># Performance metrics</em>
log "Collecting performance metrics"
DB_SIZE=$(wp --path="$WP_PATH" db size --human-readable --format=json | jq -r '.Size')
log "Database size: $DB_SIZE"

log "Performance optimization completed"
</code></pre>



<h2 class="wp-block-heading" id="related-links">Related Links</h2>



<ul class="wp-block-list">
<li><a href="https://developer.wordpress.org/cli/commands/">WP-CLI Performance Commands</a></li>



<li><a href="https://wordpress.org/support/article/optimization/">WordPress Performance Best Practices</a></li>



<li><a href="https://developer.wordpress.org/advanced-administration/upgrade/optimizing/">Database Optimization Guide</a></li>



<li><a href="https://developer.wordpress.org/advanced-administration/performance/cache/">WordPress Caching Strategies</a></li>



<li><a href="https://querymonitor.com/">Query Monitor Plugin</a></li>
</ul>
<p>The post <a href="https://wpclimastery.com/blog/optimize-wordpress-performance-with-wp-cli-15-proven-techniques/">Optimize WordPress Performance with WP-CLI: 15 Proven Techniques</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wpclimastery.com/blog/optimize-wordpress-performance-with-wp-cli-15-proven-techniques/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
