Tag pages and author archives can be seen as duplicate content by Google. Noindex them to protect SEO. Add to functions.php: add_action(‘wp_head’, function() { if (is_tag() || is_author() || is_date()) { echo ”; } }); Or Disable Archives Completely: // Redirect tag pages to homepage add_action(‘template_redirect’, function() { if (is_tag()) { wp_redirect(home_url(), 301); exit; } […]
Tag: WordPress Tips
WordPress: Use Heartbeat API Control to Reduce CPU Usage by 80%
WordPress Heartbeat API pings server every 15-60 seconds causing CPU spikes. Slow it down or disable. Add to functions.php: // Reduce heartbeat frequency add_filter(‘heartbeat_settings’, function($settings) { $settings[‘interval’] = 60; // From 15-60 to 60 seconds return $settings; }); // Disable on frontend only (keep for editor autosave) add_action(‘init’, function() { if (!is_admin()) { wp_deregister_script(‘heartbeat’); } […]
WordPress: Use Action Scheduler for Background Processing
Running heavy tasks on page load slows site. Action Scheduler queues tasks to run in background. Install: Built into WooCommerce, or install standalone “Action Scheduler” plugin Schedule Task: // Schedule single action as_schedule_single_action( time() + 3600, // 1 hour from now ‘my_custom_hook’, array(‘user_id’ => 123) // Arguments ); // Schedule recurring action (daily) as_schedule_recurring_action( time(), […]
WordPress: Use Object Caching with Redis to Speed Up Dynamic Sites
Database queries on every page load are slow. Redis caches objects in memory for instant access. Install Redis Plugin: “Redis Object Cache” by Till Krüss Setup Redis Server: # Ubuntu/Debian sudo apt install redis-server sudo systemctl start redis sudo systemctl enable redis Configure WordPress (wp-config.php): define(‘WP_REDIS_HOST’, ‘127.0.0.1’); define(‘WP_REDIS_PORT’, 6379); define(‘WP_CACHE’, true); Enable in Plugin: Settings […]
WordPress: Use WP-CLI to Manage WordPress from Command Line
Clicking through admin for repetitive tasks is slow. WP-CLI automates everything from terminal. Install: curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp Common Commands: # Install plugin wp plugin install contact-form-7 –activate # Update all plugins wp plugin update –all # Create user wp user create john john@example.com –role=author # Search and replace […]
WordPress: Use wp_mail() SMTP to Fix Email Delivery Issues
WordPress emails going to spam or not sending? PHP mail() is unreliable. Use SMTP instead. Install Plugin: “WP Mail SMTP” or “Easy WP SMTP” Or Add to functions.php: add_action(‘phpmailer_init’, function($phpmailer) { $phpmailer->isSMTP(); $phpmailer->Host = ‘smtp.gmail.com’; $phpmailer->SMTPAuth = true; $phpmailer->Port = 587; $phpmailer->Username = ‘your-email@gmail.com’; $phpmailer->Password = ‘your-app-password’; $phpmailer->SMTPSecure = ‘tls’; $phpmailer->From = ‘your-email@gmail.com’; $phpmailer->FromName = […]
WordPress: Use WP_Query Instead of query_posts for Custom Loops
query_posts() breaks main query and causes issues. WP_Query is the proper way to create custom loops. Wrong Way (Don’t Use): query_posts(‘cat=5&posts_per_page=10’); // Breaks pagination, conflicts with main query Right Way: $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 10, ‘category__in’ => array(5) ); $custom_query = new WP_Query($args); if ($custom_query->have_posts()) { while ($custom_query->have_posts()) { $custom_query->the_post(); the_title(); […]
WordPress: Use add_image_size() to Create Custom Thumbnail Sizes
WordPress default thumbnail sizes don’t fit your design? Create custom sizes. Add to functions.php: // Create custom thumbnail size add_image_size(‘custom-thumb’, 400, 300, true); // Parameters: name, width, height, crop (true/false) // Multiple sizes add_image_size(‘hero-image’, 1920, 600, true); add_image_size(‘product-thumb’, 300, 300, true); add_image_size(‘blog-featured’, 800, 400, true); Use in Templates: the_post_thumbnail(‘custom-thumb’); // Or get URL: $url = […]
WordPress: Show Different Menus to Logged-In vs Logged-Out Users
Want different navigation for members vs visitors? WordPress has built-in conditional menu display. Create Two Menus: Appearance → Menus 1. “Public Menu” (for visitors) 2. “Member Menu” (for logged-in users) Add to functions.php: function conditional_menu() { if (is_user_logged_in()) { wp_nav_menu(array(‘theme_location’ => ‘member-menu’)); } else { wp_nav_menu(array(‘theme_location’ => ‘public-menu’)); } } In header.php, replace: <?php wp_nav_menu(); […]
WordPress: Add Custom Login Logo Without Plugin Using functions.php
Want branded login page? Add custom logo with a few lines of code – no plugin needed. Add to functions.php: function custom_login_logo() { echo ‘<style type=”text/css”> #login h1 a { background-image: url(‘ . get_stylesheet_directory_uri() . ‘/images/logo.png); background-size: contain; width: 300px; height: 100px; } </style>’; } add_action(‘login_enqueue_scripts’, ‘custom_login_logo’); Change Logo URL: function custom_login_url() { return home_url(); […]
WordPress: Disable Post Revisions to Reduce Database Bloat
WordPress saves every draft edit as revision. Posts with 100+ revisions bloat your database. Limit Revisions in wp-config.php: // Keep only last 3 revisions define(‘WP_POST_REVISIONS’, 3); // Or disable completely define(‘WP_POST_REVISIONS’, false); Add above /* That’s all, stop editing! */ line. Clean Existing Revisions: Install “WP-Optimize” plugin → Database tab → Remove all post revisions […]
WordPress: Enable Maintenance Mode Without Plugins Using One Line of Code
Updating your site and want to show “Coming Soon” page? No plugin needed. Add to wp-config.php: define(‘WP_MAINTENANCE_MODE’, true); Visitors see default maintenance page. You (logged in as admin) see site normally. Custom Message: Create .maintenance file in WordPress root: <?php $upgrading = time(); ?> <h1>Site Under Maintenance</h1> <p>We’ll be back soon!</p> Remove: Delete the define […]
WordPress: Add Custom Code Without Editing Theme Files Using Code Snippets Plugin
Adding custom PHP to functions.php? Theme updates will erase your code. Use Code Snippets plugin instead. Setup: 1. Install “Code Snippets” plugin 2. Snippets → Add New 3. Paste your PHP code 4. Activate Why Better: // Your code survives theme updates // Can enable/disable snippets without deleting // Organized library of all custom code […]
WordPress: Speed Up Admin Dashboard by Disabling Heartbeat API
WordPress admin panel sluggish and using 100% CPU? The Heartbeat API polls your server every 15 seconds for autosave and notifications, eating resources. What Heartbeat Does: Every 15 seconds: – Check for new comments – Check for plugin updates – Autosave post drafts – Notify about other users editing same post – Trigger scheduled tasks […]
Recover Deleted WordPress Posts from Database (Even Without Backups)
Accidentally permanently deleted a post? If you acted within 30 days and your host hasn’t optimized the database, there’s a good chance it’s still recoverable. How WordPress “Deletes” Posts: When you empty trash, WordPress doesn’t immediately erase the post row. It updates the post_status to ‘trash’ first, then later to ‘inherit’ (for revisions). The actual […]
Stop WordPress Comment Spam Without Plugins Using This .htaccess Rule
Getting hundreds of spam comments daily? Here’s a plugin-free solution that blocks 95% of spam bots at the server level. The Problem: Most spam bots post comments by directly hitting your wp-comments-post.php file, bypassing your website’s front-end entirely. Anti-spam plugins catch this AFTER it reaches WordPress, wasting server resources processing garbage requests. The Solution – […]














