Skip to content
  • Quick Ref
  • Contact
  • About
wpcanyon.com

wpcanyon.com

Author: Admin

Fix “Maximum execution time of 30 seconds exceeded” in WordPress

Posted on August 19, 2025 By Admin No Comments on Fix “Maximum execution time of 30 seconds exceeded” in WordPress

Fix “Maximum execution time of 30 seconds exceeded” in WordPress

If you encounter the error “Maximum execution time of 30 seconds exceeded” in WordPress, it means a PHP script is taking too long to run and is being stopped by the server. This often happens during plugin updates, backups, or importing large files. The quick fix is to increase the PHP maximum execution time limit so scripts have more time to complete.

Quick Fix

  1. Access your WordPress root directory via FTP or file manager.
  2. Edit or create a php.ini or .user.ini file.
  3. Add or update this line to increase the time limit (e.g., 300 seconds):
max_execution_time = 300
  1. If you cannot edit php.ini, add this line to your wp-config.php file instead:
set_time_limit(300);
  1. Save changes and test your site or process again.

Why This Happens

PHP scripts have a maximum execution time to prevent poorly written code from running indefinitely and overloading the server. The default is often set to 30 seconds on many shared hosting environments. When WordPress or a plugin runs a process that takes longer—like importing large data, running backups, or complex queries—the script hits this limit and stops, causing the error.

Increasing the max_execution_time gives scripts more time to finish. However, setting it too high may affect server performance, so adjust carefully based on your needs.

Step-by-step Guide to Fix the Error

1. Using php.ini or .user.ini (Recommended)

This method works if you have access to your PHP configuration files.

  1. Connect to your server using FTP or your hosting control panel file manager.
  2. Navigate to your WordPress root directory (where wp-config.php is located).
  3. Look for a php.ini or .user.ini file. If none exists, create a new file named php.ini or .user.ini.
  4. Edit the file and add or update the following line:
max_execution_time = 300

This sets the maximum execution time to 300 seconds (5 minutes).

  1. Save the file and upload it back to the server if using FTP.
  2. Restart your web server if you have control over it (not always possible on shared hosting).
  3. Test your WordPress site or the process that caused the error.

2. Using wp-config.php

If you cannot access or modify php.ini, you can try increasing the time limit via WordPress configuration.

  1. Access your WordPress root directory.
  2. Edit the wp-config.php file.
  3. Add the following line near the top, just after the opening <?php tag:
set_time_limit(300);
  1. Save the file and upload it back.
  2. Test your site or process again.

3. For Nginx Servers

Nginx does not use php.ini directly but you can increase PHP-FPM timeout settings.

  1. Access your server via SSH.
  2. Edit your PHP-FPM pool configuration file, usually located at:
/etc/php/7.x/fpm/pool.d/www.conf

(Replace 7.x with your PHP version.)

  1. Find and update these values:
request_terminate_timeout = 300s
max_execution_time = 300
  1. Save the file.
  2. Restart PHP-FPM and Nginx:
sudo systemctl restart php7.x-fpm
sudo systemctl restart nginx

Replace php7.x-fpm with your PHP-FPM service name.

4. For Apache Servers

Apache usually respects php.ini or .htaccess overrides.

  1. Access your WordPress root directory.
  2. Edit or create a .htaccess file.
  3. Add this line:
php_value max_execution_time 300
  1. Save and upload the file.
  2. Restart Apache if you have server access:
sudo systemctl restart apache2

On shared hosting, this restart is handled automatically.

5. Using cPanel

  1. Log in to your cPanel dashboard.
  2. Go to Select PHP Version or MultiPHP INI Editor.
  3. Find the max_execution_time setting.
  4. Increase the value to 300 or higher.
  5. Save changes.

6. Using Plesk

  1. Log in to your Plesk panel.
  2. Go to Domains > select your domain > PHP Settings.
  3. Find max_execution_time and increase it.
  4. Save changes.

Works on

Environment Applicable Fix
Apache (shared/dedicated) .htaccess, php.ini, wp-config.php
Nginx with PHP-FPM php.ini, PHP-FPM config, wp-config.php
cPanel Hosting
…
Fixes & Errors

Change WordPress admin login URL (pros/cons & safe method)

Posted on August 19, 2025 By Admin No Comments on Change WordPress admin login URL (pros/cons & safe method)

Change WordPress Admin Login URL (Pros/Cons & Safe Method)

By default, WordPress admin login pages are accessed via /wp-login.php or /wp-admin/. This common URL is a frequent target for brute force attacks and automated bots. Changing your WordPress login URL can improve security by obscurity, but it must be done carefully to avoid locking yourself out or breaking your site.

This guide explains how to change WordPress login URL safely, the pros and cons of doing so, and provides step-by-step instructions to implement the change without causing issues.

Quick Fix: Change WordPress Login URL Safely

  1. Backup your WordPress site and database.
  2. Install a trusted plugin like WPS Hide Login or iThemes Security.
  3. Configure the plugin to set a custom login URL (e.g., /my-login).
  4. Save changes and test the new login URL in a private/incognito browser.
  5. Bookmark the new login URL and avoid using the default /wp-login.php.

Why Change the WordPress Login URL?

  • Reduce brute force attacks: Bots often target the default login URL to guess passwords.
  • Hide login page from casual attackers: Changing the URL adds a layer of obscurity.
  • Lower server load: Fewer login attempts on the default URL reduce resource usage.

However, changing the login URL is not a foolproof security solution. It should be combined with strong passwords, two-factor authentication, and other security best practices.

Pros and Cons of Changing the WordPress Login URL

Pros Cons
Reduces automated login attempts and brute force attacks. If misconfigured, you may lock yourself out of the admin area.
Improves security by obscurity. Some plugins or themes might rely on default login URLs and break.
Decreases server load caused by repeated login requests. Requires remembering or bookmarking the new login URL.

Step-by-Step: How to Change WordPress Login URL Safely

Follow these steps to safely change your WordPress login URL using a plugin. This method avoids editing core files or .htaccess rules, which can cause errors.

  1. Backup Your Site
    Before making any changes, backup your WordPress files and database using your hosting control panel or a plugin like UpdraftPlus.
  2. Install the WPS Hide Login Plugin
    Navigate to Plugins > Add New in your WordPress dashboard. Search for WPS Hide Login, install, and activate it.
  3. Configure the New Login URL
    Go to Settings > WPS Hide Login. Enter your desired login slug, for example my-login, in the Login URL field.
    my-login

    The logout and redirect URLs will update automatically.

  4. Save Changes
    Click Save Changes at the bottom of the page.
  5. Test the New Login URL
    Open a private or incognito browser window and visit https://yourdomain.com/my-login. Confirm you can access the login page.
  6. Do Not Use Default URLs
    Attempting to access /wp-login.php or /wp-admin/ will now redirect or show a 404 error, depending on plugin settings.

Verification: Confirm Your Login URL Change Works

  • Try logging in with the new URL from different browsers and devices.
  • Ensure you can log out and log back in without issues.
  • Check that no plugins or themes break due to the URL change.
  • Verify your security plugins or firewall rules do not block the new login URL.

If you encounter problems, disable the plugin via FTP or your hosting file manager by renaming its folder in /wp-content/plugins/ to regain access.

Works On

  • Web servers: Apache, Nginx, LiteSpeed
  • Hosting control panels: cPanel, Plesk, DirectAdmin
  • WordPress versions: 4.9 and above (tested with latest versions)
  • Compatible with most themes and plugins that do not hardcode login URLs

FAQ

Q: Can I change the login URL manually without a plugin?
A: It is possible but not recommended. Manual changes involve editing core files or .htaccess rules, which can cause errors and are overwritten during updates.
Q: Will changing the login URL improve my site’s security?
Changing the login URL adds a layer of obscurity and reduces automated attacks, but it should be combined with strong passwords, two-factor authentication, and security plugins.
Q: What if I forget the new login URL?
If you forget the custom login URL, you can disable the plugin via FTP by renaming its folder in /wp-content/plugins/. This restores the default login URLs.
Q: Does changing the login URL affect WooCommerce or other plugins?
Most plugins, including WooCommerce, do not rely on the login URL and will continue working normally. However, test your site after the change to ensure compatibility.
Q: Can I use security plugins to change the login URL?
Yes, many security plugins like iThemes Security and All In One WP Security offer login URL changing features with additional security options.
…
Admin & Blocks

Preload fonts and critical CSS in WordPress

Posted on August 19, 2025 By Admin No Comments on Preload fonts and critical CSS in WordPress

Preload Fonts and Critical CSS in WordPress

Preloading fonts and critical CSS in WordPress improves your website’s loading speed and user experience by instructing browsers to fetch these essential resources early. This reduces render-blocking delays and prevents flash of unstyled text (FOUT), making your site appear faster and smoother.

Quick Fix: How to Preload Fonts and Critical CSS in WordPress

  1. Identify the fonts and critical CSS files your site uses.
  2. Add <link rel="preload"> tags for fonts and critical CSS in your theme’s functions.php or via a plugin.
  3. Ensure proper as attributes and crossorigin settings for fonts.
  4. Test your site with tools like Google PageSpeed Insights to confirm preloading works.

Why This Happens

By default, browsers discover fonts and CSS files during HTML parsing, which can delay their download and block rendering. Fonts especially can cause a flash of invisible or unstyled text if not loaded early. Critical CSS controls the initial page layout and styling; if delayed, users see unstyled content or layout shifts. Preloading tells browsers to prioritize these resources, reducing delays and improving perceived performance.

Requirements

  • Access to your WordPress theme’s functions.php file or a site-specific plugin.
  • Basic knowledge of HTML and WordPress theme development.
  • Understanding of your site’s fonts and CSS files (check browser DevTools).

Step-by-step: Preload Fonts and Critical CSS in WordPress

  1. Identify Fonts and Critical CSS Files
    Use your browser’s Developer Tools (Network tab) to find font files (e.g., .woff2, .woff) and the CSS file(s) containing critical styles. Critical CSS is usually the minimal CSS needed to render above-the-fold content.
  2. Add Preload Tags for Fonts
    Open your theme’s functions.php file or create a site-specific plugin. Add the following code to insert preload headers for your font files:
    function wp_preload_fonts() {
        echo '<link rel="preload" href="' . get_template_directory_uri() . '/fonts/myfont.woff2" as="font" type="font/woff2" crossorigin="anonymous">' . "n";
    }
    add_action('wp_head', 'wp_preload_fonts');

    Replace myfont.woff2 and path with your actual font file location.

  3. Preload Critical CSS
    If you have a separate critical CSS file, preload it similarly:
    function wp_preload_critical_css() {
        echo '<link rel="preload" href="' . get_template_directory_uri() . '/css/critical.css" as="style">' . "n";
        echo '<link rel="stylesheet" href="' . get_template_directory_uri() . '/css/critical.css">' . "n";
    }
    add_action('wp_head', 'wp_preload_critical_css');

    This preloads the critical CSS and immediately applies it.

  4. Combine Preloads
    You can combine font and critical CSS preloads in one function:
    function wp_preload_assets() {
        // Preload font
        echo '<link rel="preload" href="' . get_template_directory_uri() . '/fonts/myfont.woff2" as="font" type="font/woff2" crossorigin="anonymous">' . "n";
        // Preload critical CSS
        echo '<link rel="preload" href="' . get_template_directory_uri() . '/css/critical.css" as="style">' . "n";
        echo '<link rel="stylesheet" href="' . get_template_directory_uri() . '/css/critical.css">' . "n";
    }
    add_action('wp_head', 'wp_preload_assets');
  5. Test Your Site
    Use Google PageSpeed Insights, WebPageTest, or browser DevTools to verify your fonts and critical CSS are preloaded. Look for rel="preload" tags in the page source and check the Network tab for early loading.

Common Pitfalls

  • Missing crossorigin attribute on fonts: Fonts served from your domain or CDN require crossorigin="anonymous" to avoid CORS issues.
  • Incorrect as attribute: Use as="font" for fonts and as="style" for CSS. Wrong values cause browsers to ignore preloading.
  • Preloading too many files: Only preload critical fonts and CSS to avoid wasting bandwidth and blocking other resources.
  • Not applying critical CSS after preload: Preloading CSS alone does not apply it. You must include a stylesheet link or inline the CSS.
  • Using plugins that conflict: Some optimization plugins may already handle preloading. Check plugin settings to avoid duplication.

Works on

This method works on all major web servers and hosting control panels including:

  • Apache
  • Nginx
  • LiteSpeed
  • cPanel
  • Plesk

Because it uses standard WordPress hooks and HTML tags, it is compatible with almost all WordPress setups.

FAQ

Q: Can I preload Google Fonts in WordPress?
A: Yes, but you must self-host the fonts or use the Google Fonts API preload method carefully. Self-hosting fonts allows you to preload them reliably with rel="preload".
Q: How do I generate critical CSS for my WordPress site?
A: Use tools like CriticalCSS.com, SiteLocity Critical CSS Generator, or plugins like Autoptimize that can extract critical CSS automatically.
Q: Will preloading fonts increase my bandwidth usage?
A: Preloading itself does not increase bandwidth but causes fonts to be fetched earlier. Avoid preloading unnecessary fonts to prevent wasted bandwidth.
Q: Can
…
Speed & Security

WooCommerce: Force login to purchase (hide price for guests)

Posted on August 19, 2025 By Admin No Comments on WooCommerce: Force login to purchase (hide price for guests)

WooCommerce: Force Login to Purchase (Hide Price for Guests)

If you want to restrict your WooCommerce store so that only logged-in users can see product prices and make purchases, this tutorial will show you how to do it quickly and effectively. By forcing users to log in before viewing prices or adding products to the cart, you can create a members-only shopping experience or better control customer access.

Quick Fix: Require Login to Purchase in WooCommerce

  1. Add a code snippet to your theme’s functions.php file or a site-specific plugin.
  2. Hide product prices and add-to-cart buttons for guests (non-logged-in users).
  3. Redirect guests to the login page when they try to access the cart or checkout.

Why This Happens

By default, WooCommerce displays product prices and allows purchases to all visitors, regardless of login status. However, some stores want to restrict this functionality to registered users only. WooCommerce does not have a built-in setting for this, so you need to customize it by adding code that hides prices and disables purchasing for guests.

This approach is common for wholesale stores, membership sites, or private catalogs where pricing and purchasing should be exclusive.

Requirements

  • WooCommerce installed and active on your WordPress site.
  • Access to your theme’s functions.php file or the ability to add custom PHP snippets via a plugin like Code Snippets.
  • Basic understanding of WordPress and WooCommerce templates.

Step-by-Step: Force Login to Purchase in WooCommerce

  1. Backup your site before making any code changes.
  2. Open your theme’s functions.php file or a site-specific plugin editor.
  3. Add the following code snippet:
<?php
// Hide prices and add to cart button for guests
function wc_hide_price_add_to_cart_for_guests() {
    if ( ! is_user_logged_in() ) {
        remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
        add_filter( 'woocommerce_get_price_html', '__return_empty_string' );
        add_filter( 'woocommerce_cart_item_price', '__return_empty_string' );
        add_filter( 'woocommerce_cart_item_subtotal', '__return_empty_string' );
    }
}
add_action( 'wp', 'wc_hide_price_add_to_cart_for_guests' );

// Redirect guests to login page when trying to access cart or checkout
function wc_redirect_non_logged_users() {
    if ( ! is_user_logged_in() && ( is_cart() || is_checkout() ) ) {
        wp_safe_redirect( wp_login_url( wc_get_page_permalink( is_checkout() ? 'checkout' : 'cart' ) ) );
        exit;
    }
}
add_action( 'template_redirect', 'wc_redirect_non_logged_users' );
?>
  1. Save the file and test your site by logging out and visiting product pages, the cart, and checkout.

Common Pitfalls

  • Child Theme vs Parent Theme: Adding code to a parent theme’s functions.php can be overwritten on updates. Use a child theme or a site-specific plugin.
  • Cache Issues: If you use caching plugins or server caching, clear caches after adding the code to see changes immediately.
  • Login Redirect Loops: Ensure the login redirect URL is correct to avoid redirect loops.
  • Custom Themes or Plugins: Some themes or plugins might override WooCommerce hooks, so test thoroughly.

Works On

This solution works on all standard WooCommerce setups running on:

  • Apache and Nginx web servers
  • LiteSpeed servers
  • Hosting control panels like cPanel and Plesk
  • Any WordPress environment where you can add PHP code snippets

FAQ

Q: Can I customize the login redirect URL?
A: Yes, modify the wp_login_url() function parameter to any URL you want users to land on after login.
Q: Will this hide prices on all product types?
A: Yes, the snippet hides prices and add-to-cart buttons for all product types for guests.
Q: Can I show a custom message instead of hiding prices?
A: Yes, you can replace the price filters with a custom message by hooking into woocommerce_get_price_html and returning your message.
Q: Does this affect logged-in users?
No, logged-in users will see prices and can purchase products normally.
Q: Is there a plugin alternative?
Yes, some plugins offer membership or wholesale features that include login-to-purchase restrictions, but this code snippet is lightweight and free.
…
WooCommerce How‑tos

Increase upload_max_filesize (Uploaded file exceeds the upload_max_filesize directive)

Posted on August 19, 2025 By Admin No Comments on Increase upload_max_filesize (Uploaded file exceeds the upload_max_filesize directive)

Increase upload_max_filesize (Uploaded file exceeds the upload_max_filesize directive)

If you encounter the error “Uploaded file exceeds the upload_max_filesize directive” in WordPress, it means your server’s PHP configuration limits the maximum file size you can upload. This often blocks you from uploading large media files or plugins. The quick fix is to increase the upload_max_filesize value in your PHP settings.

Quick Fix

  1. Edit your php.ini file (or create one if it doesn’t exist) and add or update this line:
    upload_max_filesize = 64M
  2. Also increase post_max_size to the same or larger value:
    post_max_size = 64M
  3. Restart your web server (Apache, Nginx, LiteSpeed) to apply changes.
  4. Verify the new limits in WordPress by going to Media > Add New or using a PHP info plugin.

Why this happens

PHP has built-in limits on file upload sizes to prevent server overload and abuse. The upload_max_filesize directive controls the maximum size of an uploaded file, while post_max_size controls the maximum size of POST data allowed. If your file exceeds these limits, PHP rejects the upload and WordPress shows the error.

By default, many hosting providers set these values low (e.g., 2MB or 8MB) to conserve resources. To upload larger files, you must increase these limits manually.

Step-by-step

1. For Apache or LiteSpeed servers

  1. Locate your php.ini file. Common locations:
    • /etc/php/7.x/apache2/php.ini
    • /usr/local/lib/php.ini
    • Use phpinfo() to find the loaded config file.
  2. Edit the php.ini file and update or add:
    upload_max_filesize = 64M
    post_max_size = 64M
    memory_limit = 128M
    max_execution_time = 300
    max_input_time = 300
  3. Save the file and restart Apache or LiteSpeed:
    sudo systemctl restart apache2
    # or for LiteSpeed
    sudo systemctl restart lsws
  4. Check changes with a PHP info file or WordPress media uploader.

2. For Nginx servers

  1. Edit your PHP-FPM php.ini file (location similar to Apache).
  2. Update the same directives as above:
    upload_max_filesize = 64M
    post_max_size = 64M
    memory_limit = 128M
    max_execution_time = 300
    max_input_time = 300
  3. Edit your Nginx site configuration file (e.g., /etc/nginx/sites-available/example.com) and add or update:
    client_max_body_size 64M;
  4. Restart PHP-FPM and Nginx:
    sudo systemctl restart php7.x-fpm
    sudo systemctl restart nginx
  5. Verify upload limits in WordPress.

3. Using cPanel

  1. Log in to your cPanel dashboard.
  2. Go to MultiPHP INI Editor under the Software section.
  3. Select your domain from the dropdown.
  4. Set upload_max_filesize and post_max_size to your desired values (e.g., 64M).
  5. Save the changes.
  6. Check your WordPress upload limits.

4. Using Plesk

  1. Log in to Plesk.
  2. Go to Domains > example.com > PHP Settings.
  3. Find upload_max_filesize and post_max_size and increase their values.
  4. Save the settings.
  5. Test upload limits in WordPress.

Works on

Server Control Panel Notes
Apache cPanel, Plesk, Manual Requires php.ini edit and server restart
Nginx cPanel, Plesk, Manual Requires php.ini and nginx.conf edits + restarts
LiteSpeed cPanel, Manual Similar to Apache, restart LiteSpeed after changes

FAQ

  1. Q: I increased upload_max_filesize but still get the error. Why?

    A: You must also increase post_max_size and ensure your web server (Nginx or Apache) allows larger uploads (e.g., client_max_body_size in Nginx). Restart your server after changes.

  2. Q: Can I increase upload limits via .htaccess?

    A: Only on Apache servers with PHP running as an Apache module. Add these lines to your .htaccess:

    php_value upload_max_filesize 64M
    php_value post_max_size 64M
  3. Q: How do I check current upload limits?

    A: Use a PHP info plugin in WordPress or create a phpinfo.php file with:

    <?php phpinfo(); ?>

    Then open it in your browser and look for upload_max_filesize

…
Fixes & Errors

Disable comments sitewide (and close on old posts)

Posted on August 19, 2025 By Admin No Comments on Disable comments sitewide (and close on old posts)

Disable Comments Sitewide (and Close on Old Posts) in WordPress

Comments can sometimes attract spam, require moderation, or simply no longer fit the purpose of your WordPress site. Disabling comments sitewide and closing comments on older posts is a straightforward way to maintain control over user interaction and reduce maintenance. This guide shows you how to quickly disable comments across your entire WordPress site and automatically close comments on posts older than a specified number of days.

Quick Fix: Disable Comments Sitewide

  1. Go to your WordPress admin dashboard.
  2. Navigate to Settings > Discussion.
  3. Uncheck Allow people to submit comments on new posts.
  4. Save changes.
  5. To disable comments on existing posts, use the bulk edit feature or apply a code snippet (see below).
  6. To close comments on old posts automatically, add a custom function to your theme’s functions.php file or a site-specific plugin.

Why This Happens

By default, WordPress allows comments on new posts unless disabled manually. Existing posts retain their comment status unless changed individually or programmatically. Older posts may continue to accept comments indefinitely, which can lead to spam or outdated discussions. Disabling comments sitewide and closing them on older posts helps maintain site cleanliness and reduces moderation workload.

Step-by-Step: Disable Comments Sitewide and Close on Old Posts

1. Disable Comments on New Posts via Settings

This prevents comments on all future posts.

Dashboard > Settings > Discussion
- Uncheck "Allow people to submit comments on new posts"
- Save Changes

2. Disable Comments on Existing Posts in Bulk

Use WordPress bulk edit to disable comments on existing posts:

  1. Go to Posts > All Posts.
  2. Select all posts (increase posts per page if needed).
  3. Choose Edit from the Bulk Actions dropdown and click Apply.
  4. Set Comments to Do not allow.
  5. Click Update.

3. Programmatically Close Comments on Old Posts

Add the following code snippet to your theme’s functions.php file or a site-specific plugin. This will automatically close comments on posts older than 30 days (adjustable):

function close_comments_on_old_posts( $open, $post_id ) {
    $days = 30; // Number of days after which comments close
    $post = get_post( $post_id );
    if ( 'post' === $post-post_type ) {
        $post_age = ( time() - strtotime( $post-post_date ) ) / DAY_IN_SECONDS;
        if ( $post_age $days ) {
            return false; // Close comments
        }
    }
    return $open;
}
add_filter( 'comments_open', 'close_comments_on_old_posts', 10, 2 );

4. Disable Comments on Other Content Types

To disable comments on pages or custom post types, extend the bulk edit or use this snippet to disable comments sitewide:

function disable_comments_everywhere() {
    // Disable support for comments and trackbacks in post types
    foreach ( get_post_types() as $post_type ) {
        if ( post_type_supports( $post_type, 'comments' ) ) {
            remove_post_type_support( $post_type, 'comments' );
            remove_post_type_support( $post_type, 'trackbacks' );
        }
    }
}
add_action( 'admin_init', 'disable_comments_everywhere' );

// Close comments on front-end
function filter_comments_open( $open, $post_id ) {
    return false;
}
add_filter( 'comments_open', 'filter_comments_open', 20, 2 );
add_filter( 'pings_open', 'filter_comments_open', 20, 2 );

Common Pitfalls

  • Theme or plugin overrides: Some themes or plugins may override comment settings. Check for theme options or plugin settings that enable comments independently.
  • Cached pages: If you use caching plugins or server caching, changes may not appear immediately. Clear caches after applying changes.
  • Bulk edit limits: Bulk editing posts is limited by the number of posts shown per page. Increase the number of posts per page or repeat the process for all pages.
  • Child theme usage: When adding code snippets, use a child theme or a site-specific plugin to avoid losing changes after theme updates.

Works on

This method works on all standard WordPress setups regardless of the web server:

  • Apache
  • Nginx
  • LiteSpeed
  • cPanel and Plesk hosting environments
  • Multisite WordPress installations (note: bulk edit applies per site)

FAQ

Q: Will disabling comments delete existing comments?
No, disabling comments only prevents new comments. Existing comments remain visible unless you delete them manually.
Q: Can I disable comments only on pages and not posts?
Yes. You can selectively disable comments by modifying the code snippet to target only the ‘page’ post type or use bulk edit on pages only.
Q: How do I re-enable comments later?
Simply reverse the changes: enable comments in Settings > Discussion, remove or comment out the code snippets, and bulk edit posts/pages to allow comments again.
Q: Does this method affect pingbacks and trackbacks?
The provided code disables both comments and pingbacks/trackbacks. You can adjust the filters if you want to keep pingbacks enabled.
Q: Is there a plugin alternative?
Yes, plugins like “Disable Comments” offer UI-based options to disable comments sitewide or selectively. However, manual code snippets provide more control and avoid plugin bloat.
…
Admin & Blocks

Cloudflare cache rules for WordPress (no admin caching)

Posted on August 19, 2025 By Admin No Comments on Cloudflare cache rules for WordPress (no admin caching)

Cloudflare Cache Rules for WordPress (No Admin Caching)

If you use Cloudflare with your WordPress site, you might notice issues when the WordPress admin dashboard or login pages get cached. This can cause outdated content, login problems, or broken admin functionality. The quick fix is to set up Cloudflare cache rules that exclude the WordPress admin area and login pages from caching, ensuring smooth backend operations while still benefiting from caching on the public site.

Quick Fix

  1. Log in to your Cloudflare dashboard.
  2. Navigate to the “Rules” section and select “Page Rules” or “Cache Rules” (depending on your Cloudflare plan).
  3. Create rules to bypass cache for URLs related to WordPress admin and login:
    • example.com/wp-admin/*
    • example.com/wp-login.php*
  4. Set these rules to Bypass Cache or Cache Level: Bypass.
  5. Save and deploy the rules.
  6. Test by logging in and accessing the admin dashboard to confirm no caching issues.

Why This Happens

Cloudflare caches static content by default to speed up your website. However, WordPress admin pages and login screens are dynamic and personalized. If Cloudflare caches these pages, users may see stale content or be unable to log in properly. This happens because Cloudflare does not differentiate between public and admin URLs unless explicitly told to do so. Therefore, you need to create cache rules that exclude admin and login URLs from caching.

Requirements

  • A Cloudflare account with your WordPress site added.
  • Access to the Cloudflare dashboard to create cache or page rules.
  • Basic understanding of WordPress URL structure.

Step-by-Step: Setting Up Cloudflare Cache Rules for WordPress Admin

  1. Log in to Cloudflare at https://dash.cloudflare.com.
  2. Select your domain from the list.
  3. Go to the “Rules” tab in the dashboard sidebar.
  4. Create a new Page Rule or Cache Rule (depending on your Cloudflare plan):
    • Click Create Page Rule or Create Cache Rule.
  5. Enter the URL pattern for the WordPress admin area:
  6. https://example.com/wp-admin/*
  7. Set the rule action to: Cache Level: Bypass or Bypass Cache.
  8. Save and deploy the rule.
  9. Create a second rule for the login page:
  10. https://example.com/wp-login.php*
  11. Set the same bypass cache action.
  12. Save and deploy.
  13. Optional: Add rules to bypass caching for REST API and AJAX calls:
  14. https://example.com/wp-json/*
    https://example.com/admin-ajax.php*
  15. Test your site: Log in and navigate the admin dashboard to confirm no caching issues.

Code Snippets for Cloudflare Cache Rules

Here are the exact URL patterns to use when creating your Cloudflare rules:

URL Pattern Cache Action Purpose
https://example.com/wp-admin/* Bypass Cache Exclude WordPress admin pages
https://example.com/wp-login.php* Bypass Cache Exclude login page
https://example.com/wp-json/* Bypass Cache Exclude REST API requests
https://example.com/admin-ajax.php* Bypass Cache Exclude AJAX requests

Note: Replace example.com with your actual domain.

Common Pitfalls

  • Not using HTTPS in URL patterns: Cloudflare rules are protocol-specific. Use https:// if your site uses SSL.
  • Incorrect wildcard usage: Use * to match any characters after the path. For example, /wp-admin/* matches all admin subpages.
  • Rule order matters: Cloudflare processes rules in order. Place bypass rules above any general caching rules.
  • Forgetting REST API and AJAX: These endpoints are critical for admin functionality and should also be excluded from caching.
  • Not clearing Cloudflare cache after changes: Purge cache to ensure new rules take effect immediately.

Works On

  • Cloudflare CDN (all plans with Page Rules or Cache Rules support)
  • WordPress sites on Apache, Nginx, LiteSpeed, or other web servers
  • Hosting control panels like cPanel, Plesk, or custom setups

FAQ

Q: Can I cache the WordPress admin area safely?
A: No, caching the admin area can cause outdated content and login issues. Always bypass cache for admin URLs.
Q: What happens if I don’t exclude wp-login.php from caching?
You may experience login failures or see cached login pages that prevent proper authentication.
Q: Do I need to exclude REST API and AJAX URLs?
Yes, these endpoints are essential for dynamic admin functions and should not be cached.
Q: How do I clear Cloudflare cache after adding rules?
Go to the “Caching” tab in Cloudflare dashboard and click “
…
Speed & Security

WooCommerce: Add a handling fee or surcharge

Posted on August 19, 2025 By Admin No Comments on WooCommerce: Add a handling fee or surcharge

WooCommerce: Add a Handling Fee or Surcharge

Adding a handling fee or surcharge to your WooCommerce store can help cover extra costs such as packaging, payment processing, or special delivery requirements. This tutorial shows you how to woocommerce add handling fee quickly and effectively using custom code snippets, ensuring the fee appears transparently during checkout.

Quick Fix: Add a Handling Fee in WooCommerce

  1. Access your WordPress theme’s functions.php file or use a site-specific plugin.
  2. Copy and paste the provided PHP code snippet to add a fixed or percentage-based handling fee.
  3. Save changes and test the checkout to confirm the fee appears correctly.

Why This Happens

WooCommerce by default does not include a handling fee option. Many store owners need to add extra charges to cover costs beyond product prices and shipping. Since WooCommerce’s built-in fees are flexible but require manual input, adding a custom handling fee via code automates this process and ensures consistent application.

Requirements

  • WooCommerce installed and active on your WordPress site.
  • Access to your theme’s functions.php file or a custom plugin for adding PHP code.
  • Basic familiarity with editing WordPress files or using a code snippet plugin.

Step-by-Step: Adding a Handling Fee in WooCommerce

1. Backup Your Site

Before making any code changes, always backup your site to avoid accidental loss or downtime.

2. Open Your Theme’s functions.php File

Use FTP, cPanel File Manager, or the WordPress theme editor to open functions.php located in your active theme folder.

3. Add the Handling Fee Code Snippet

Paste the following code at the end of the functions.php file. This example adds a fixed handling fee of $5.00 to every order:

add_action( 'woocommerce_cart_calculate_fees', 'add_handling_fee' );
function add_handling_fee() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $handling_fee = 5.00; // Fixed handling fee amount
    WC()-cart-add_fee( 'Handling Fee', $handling_fee, true, '' );
}

4. Save the File

Save your changes and upload the file back to the server if using FTP.

5. Test the Checkout

Add products to your cart and proceed to checkout. You should see the “Handling Fee” line item added to the order totals.

Optional: Percentage-Based Handling Fee

If you prefer a handling fee based on a percentage of the cart subtotal, use this code instead:

add_action( 'woocommerce_cart_calculate_fees', 'add_percentage_handling_fee' );
function add_percentage_handling_fee() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $percentage = 0.05; // 5% handling fee
    $cart_subtotal = WC()-cart-get_subtotal();
    $handling_fee = $cart_subtotal * $percentage;

    WC()-cart-add_fee( 'Handling Fee (5%)', $handling_fee, true, '' );
}

Common Pitfalls

  • Fee not showing: Ensure the code is placed in the active theme’s functions.php or a site-specific plugin, and WooCommerce is active.
  • Fee applied multiple times: The code checks for admin and AJAX contexts to prevent duplication. Avoid adding the snippet multiple times.
  • Tax settings: The third parameter in add_fee() controls if the fee is taxable. Set it to true or false depending on your tax rules.
  • Compatibility: Custom code may conflict with other plugins that modify cart fees. Test thoroughly.

Works On

Environment Compatibility
Web Servers Apache, Nginx, LiteSpeed
Hosting Panels cPanel, Plesk, DirectAdmin
WordPress Versions WooCommerce compatible versions (4.0+ recommended)

FAQ

Q1: Can I add different handling fees based on payment method?

Yes. You can check the chosen payment method using WC()-session-get('chosen_payment_method') inside the fee function and conditionally add fees.

Q2: How do I make the handling fee tax-exempt?

Set the third parameter of add_fee() to false. For example: WC()-cart-add_fee( 'Handling Fee', $fee, false );

Q3: Can I add handling fees only for specific products or categories?

Yes. Use WC()-cart-get_cart() to loop through cart items and conditionally apply fees based on product IDs or categories.

Q4: Will this handling fee appear in order emails and invoices?

Yes. WooCommerce includes fees in order totals, so the handling fee will appear in emails, invoices, and admin order details.

Q5: Is there a plugin alternative to adding handling fees?

Yes. Plugins like “WooCommerce Advanced Fees” or “WooCommerce Extra Fees Plugin” offer GUI-based fee management without coding.…

WooCommerce How‑tos

Fix WordPress posts returning 404 (pages OK)

Posted on August 19, 2025 By Admin No Comments on Fix WordPress posts returning 404 (pages OK)

Fix WordPress posts returning 404 (pages OK)

If your WordPress posts are returning 404 errors while your pages load just fine, it can be a frustrating issue that disrupts your site’s functionality and user experience. The good news is this problem usually stems from permalink or rewrite rule issues, and you can fix it quickly by resetting your permalink structure or adjusting your server configuration.

Quick Fix

  1. Log in to your WordPress admin dashboard.
  2. Go to Settings > Permalinks.
  3. Without changing anything, click the Save Changes button at the bottom.
  4. Check your posts again; the 404 errors should be resolved.

Why this happens

This issue typically occurs because WordPress’s rewrite rules are out of sync or not properly flushed. WordPress uses rewrite rules to map URLs to the correct content. When these rules are corrupted, missing, or not updated, posts URLs can return 404 errors even though pages work fine.

Common causes include:

  • Changing permalink settings without flushing rewrite rules.
  • Server configuration changes or restrictions (e.g., missing .htaccess rules on Apache or incorrect Nginx configuration).
  • Plugin conflicts that modify rewrite rules.
  • File permission issues preventing WordPress from writing to the .htaccess file.

Step-by-step

1. Reset Permalinks in WordPress Dashboard

  1. Navigate to Settings > Permalinks.
  2. Click Save Changes without modifying any settings.

This action forces WordPress to flush and regenerate rewrite rules.

2. Check and Update .htaccess File (Apache)

If resetting permalinks doesn’t fix the issue, verify your .htaccess file contains the correct WordPress rewrite rules.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Make sure the file is located in your WordPress root directory and is writable by the server.

3. Configure Nginx Rewrite Rules

If you use Nginx, WordPress permalinks require specific rewrite rules in your server configuration. Add or verify the following inside your server block:

location / {
    try_files $uri $uri/ /index.php?$args;
}

After updating Nginx config, reload Nginx:

sudo nginx -s reload

4. Check File Permissions

Ensure .htaccess (Apache) or your WordPress root directory files have correct permissions:

chmod 644 .htaccess
chmod 755 /path/to/wordpress/

Incorrect permissions can prevent WordPress from updating rewrite rules.

5. Disable Plugins Temporarily

Some plugins interfere with rewrite rules. Temporarily deactivate all plugins to check if the issue resolves:

wp plugin deactivate --all

If posts work after deactivation, reactivate plugins one by one to identify the culprit.

Works on

Environment Notes
Apache Requires correct .htaccess with WordPress rewrite rules.
Nginx Needs proper try_files directive in server block.
LiteSpeed Compatible with Apache-style .htaccess rules.
cPanel / Plesk Standard hosting control panels; ensure file permissions and rewrite modules enabled.

FAQ

Q: Why do pages work but posts return 404 errors?
A: Pages often use static URLs that don’t rely on rewrite rules as heavily as posts. If rewrite rules are broken, posts URLs break but pages can still load.
Q: Can a plugin cause posts to 404?
A: Yes, plugins that modify URLs or rewrite rules can cause conflicts leading to 404 errors on posts.
Q: How do I flush rewrite rules manually?
A: Besides saving permalinks in the dashboard, you can add flush_rewrite_rules(); in your theme’s functions.php temporarily and then remove it after the rules flush.
Q: What if I don’t have access to .htaccess or Nginx config?
A: Contact your hosting provider to ensure rewrite modules are enabled and configurations are correct.
Q: Does changing permalink structure fix the issue?
A: Sometimes changing and saving a different permalink structure forces rewrite rules to update and resolves 404 errors.
…
Fixes & Errors

Redirect author archives to homepage (or page)

Posted on August 19, 2025 By Admin No Comments on Redirect author archives to homepage (or page)

Redirect Author Archives to Homepage (or Page) in WordPress

If you want to redirect author archive WordPress pages to your homepage or a custom page, this tutorial shows you how to do it quickly and effectively. Author archives often reveal usernames or create duplicate content issues, so redirecting them can improve security and SEO.

Quick Fix

  1. Add a simple PHP snippet to your theme’s functions.php file or a site-specific plugin.
  2. Choose whether to redirect to the homepage or a custom URL.
  3. Test the author archive URLs to confirm the redirect works.

Why This Happens

By default, WordPress generates author archive pages at URLs like yoursite.com/author/username. These pages list all posts by that author. However, if you only have one author or want to hide author information for security or SEO reasons, redirecting these archives is a common approach.

Redirecting author archives prevents:

  • Exposure of usernames that can be exploited in brute force attacks.
  • Duplicate content issues that may harm SEO rankings.
  • Unnecessary archive pages that don’t add value to your site.

Requirements

  • Access to your WordPress theme files or ability to add custom code via a plugin.
  • Basic knowledge of editing PHP files safely.
  • Optional: FTP or hosting control panel access for file editing.

Step-by-step Guide to Redirect Author Archives

  1. Backup your site. Always create a backup before editing theme files.
  2. Access your theme’s functions.php file. You can do this via WordPress Admin Dashboard under Appearance > Theme Editor, or via FTP/cPanel file manager.
  3. Add the redirect code snippet. Copy and paste the following code at the end of the functions.php file:
function redirect_author_archives() {
    if (is_author()) {
        wp_redirect(home_url(), 301);
        exit;
    }
}
add_action('template_redirect', 'redirect_author_archives');

This code checks if the current page is an author archive and redirects visitors to the homepage with a permanent (301) redirect.

  1. Redirect to a custom page (optional). If you want to redirect to a specific page instead of the homepage, replace home_url() with the URL of your choice, for example:
wp_redirect(home_url('/custom-page/'), 301);
  1. Save the changes. Update the file and clear any caching plugins or server caches.
  2. Test the redirect. Visit any author archive URL like yoursite.com/author/username to confirm it redirects correctly.

Common Pitfalls

  • Editing the wrong functions.php file: Make sure you edit the active theme’s file or use a child theme to avoid losing changes on updates.
  • Cache interference: Clear browser, plugin, and server caches after adding the code to see the redirect immediately.
  • Plugin conflicts: Some SEO or redirection plugins may override this behavior. Disable them temporarily to test.
  • Incorrect URL in redirect: Ensure the URL passed to wp_redirect() is correct and includes trailing slashes if needed.

Works on

Server/Environment Compatibility
Apache Fully compatible
Nginx Fully compatible
LiteSpeed Fully compatible
cPanel / Plesk Fully compatible
Any WordPress environment Compatible as long as PHP code can be added

FAQ

  1. Can I redirect author archives without editing functions.php?

    Yes, you can use a plugin like “Redirection” or an SEO plugin with redirect features, but adding code is lightweight and efficient.

  2. Will this affect SEO negatively?

    No, a 301 redirect tells search engines the author archive pages are permanently moved, preventing duplicate content issues.

  3. How do I redirect only specific authors?

    Modify the code to check for specific author IDs or usernames before redirecting. Example:

    function redirect_specific_author_archives() {
        if (is_author('username')) {
            wp_redirect(home_url(), 301);
            exit;
        }
    }
    add_action('template_redirect', 'redirect_specific_author_archives');
    
  4. What if I want to disable author archives instead of redirecting?

    You can disable author archives by returning a 404 status or using SEO plugins to noindex those pages.

  5. Is this method safe for multisite WordPress?

    Yes, but ensure you add the code to each site’s theme or a network-activated plugin if you want it site-wide.

…
Admin & Blocks

Posts pagination

Previous 1 2 3 4 … 10 Next

Recent Posts

  • Top WordPress Themes for Blogs in 2025
  • WordPress Admin Panel Trick: Adding ID Field to the Posts Listing
  • Solution previous_posts_link and next_posts_link Not Working
  • Show Top Commentators in WordPress Without a Plugin
  • How to Style Admin Comments in WordPress

Recent Comments

    Archives

    • August 2025

    Categories

    • Admin & Blocks
    • Admin & UI
    • Automation
    • Automation & Plugins
    • Comments
    • Comparisons
    • Database & Revisions
    • Developer Snippets
    • Fixes & Errors
    • Media & Thumbnails
    • Queries & Pagination
    • Security
    • Speed & Security
    • Tips & Tricks
    • WooCommerce How‑tos
    • WordPress Snippets
    • WordPress Themes
    • Terms & Conditions
    • Affiliate Disclosure

    Copyright © 2025 wpcanyon.com.

    Powered by PressBook WordPress theme