Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Tag: WordPress Tips

Wordpress

WordPress: Add noindex to Tag and Author Pages to Prevent Duplicate Content

- 17.02.26 - ErcanOPAK comment on WordPress: Add noindex to Tag and Author Pages to Prevent Duplicate Content

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; } […]

Read More
Wordpress

WordPress: Use Heartbeat API Control to Reduce CPU Usage by 80%

- 17.02.26 - ErcanOPAK comment on 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’); } […]

Read More
Wordpress

WordPress: Use Action Scheduler for Background Processing

- 16.02.26 - ErcanOPAK comment on 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(), […]

Read More
Wordpress

WordPress: Use Object Caching with Redis to Speed Up Dynamic Sites

- 16.02.26 - ErcanOPAK comment on 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 […]

Read More
Wordpress

WordPress: Use WP-CLI to Manage WordPress from Command Line

- 15.02.26 - ErcanOPAK comment on 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 […]

Read More
Wordpress

WordPress: Use wp_mail() SMTP to Fix Email Delivery Issues

- 15.02.26 - ErcanOPAK comment on 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 = […]

Read More
Wordpress

WordPress: Use WP_Query Instead of query_posts for Custom Loops

- 15.02.26 - ErcanOPAK comment on 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(); […]

Read More
Wordpress

WordPress: Use add_image_size() to Create Custom Thumbnail Sizes

- 15.02.26 - ErcanOPAK comment on 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 = […]

Read More
Wordpress

WordPress: Show Different Menus to Logged-In vs Logged-Out Users

- 14.02.26 - ErcanOPAK comment on 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(); […]

Read More
Wordpress

WordPress: Add Custom Login Logo Without Plugin Using functions.php

- 14.02.26 - ErcanOPAK comment on 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(); […]

Read More
Wordpress

WordPress: Disable Post Revisions to Reduce Database Bloat

- 13.02.26 - ErcanOPAK comment on 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 […]

Read More
Wordpress

WordPress: Enable Maintenance Mode Without Plugins Using One Line of Code

- 13.02.26 - ErcanOPAK comment on 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 […]

Read More
Wordpress

WordPress: Add Custom Code Without Editing Theme Files Using Code Snippets Plugin

- 13.02.26 - ErcanOPAK comment on 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 […]

Read More
Wordpress

WordPress: Speed Up Admin Dashboard by Disabling Heartbeat API

- 03.02.26 - ErcanOPAK comment on 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 […]

Read More
Wordpress

Recover Deleted WordPress Posts from Database (Even Without Backups)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on 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 […]

Read More
Wordpress

Stop WordPress Comment Spam Without Plugins Using This .htaccess Rule

- 01.02.26 | 01.02.26 - ErcanOPAK comment on 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 – […]

Read More
February 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
232425262728  
« Jan    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (935)
  • How to add default value for Entity Framework migrations for DateTime and Bool (832)
  • Get the First and Last Word from a String or Sentence in SQL (826)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (717)
  • Add Constraint to SQL Table to ensure email contains @ (574)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (553)
  • Average of all values in a column that are not zero in SQL (520)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (474)
  • Find numbers with more than two decimal places in SQL (436)

Recent Posts

  • C#: Use MemoryPack for 10x Faster Serialization than JSON
  • C#: Use params ReadOnlySpan for Allocation-Free Variable Arguments
  • C#: Use ObjectPool for Reusing Expensive Objects
  • C#: Use Lazy for Expensive Object Initialization
  • SQL: Use STRING_AGG to Concatenate Rows into Comma-Separated List
  • SQL: Use Filtered Indexes to Index Only Subset of Rows
  • .NET Core: Use Result Pattern to Avoid Exceptions for Expected Errors
  • .NET Core: Use IOptions Pattern for Strongly-Typed Configuration
  • Git: Use .gitattributes to Handle Line Endings Across OS
  • Git: Use git notes to Add Comments to Commits Without Changing History

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (935)
  • How to add default value for Entity Framework migrations for DateTime and Bool (832)
  • Get the First and Last Word from a String or Sentence in SQL (826)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (717)

Recent Posts

  • C#: Use MemoryPack for 10x Faster Serialization than JSON
  • C#: Use params ReadOnlySpan for Allocation-Free Variable Arguments
  • C#: Use ObjectPool for Reusing Expensive Objects
  • C#: Use Lazy for Expensive Object Initialization
  • SQL: Use STRING_AGG to Concatenate Rows into Comma-Separated List

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com