WooCommerce登录错误信息显示在URL而非页面的问题求助
Hey George, let's tackle this strange login bug with your eshop—it’s definitely odd that only failed credential errors are showing up in the URL instead of being displayed properly on the page. Here are actionable fixes to get this sorted out:
Troubleshooting & Fixes for Login Error Display Issues
1. Verify Form Submission Method & Error Handling Logic
- First off, check if your login form uses the
GETmethod. If it does, all form data (including error messages) will get appended to the URL. Switch it toPOST—this keeps data in the request body instead of the URL, and it’s more secure too. - Look into your backend login handling code: When credentials fail, the error should be stored in a session (or temporary storage) before redirecting back to the login page. Then, the page should pull that error from the session to render it, rather than attaching it as a URL parameter.
2. Check Theme/Plugin Template Overrides
- Since your URL has
my-accountandwp-error, I’m guessing you’re using WooCommerce with WordPress. Many custom themes override the my-account/login template. Locate your theme’smyaccount/form-login.phpfile:- Make sure it includes the
<?php wc_print_notices(); ?>line—this is what WooCommerce uses to display errors. If this line is missing or commented out, errors won’t show up on the page. - Test by switching to a default theme like Storefront. If errors display correctly then, your custom theme is the culprit.
- Make sure it includes the
3. Rule Out Plugin Conflicts
- Disable all third-party plugins except WooCommerce, then test the failed login scenario. If errors show up properly, re-enable plugins one by one to find which one’s causing the conflict.
- Pay extra attention to plugins that modify login flows, add security checks, or alter session handling—these are the most likely to interfere with error display.
4. Fix Error Message Escaping & Rendering
- Your URL shows the error is URL-encoded (
<strong>ΣΦΑΛΜΑ<%2Fstrong>), meaning the backend isn’t decoding or rendering it correctly. Check your backend error handling code:- In PHP, use functions like
wp_kses_post()oresc_html()to properly handle HTML escaping, so the error message renders as readable text/HTML on the page instead of encoded junk.
- In PHP, use functions like
5. Correct Redirect Configuration
- It seems like your system is appending errors to the redirect URL instead of storing them in the session. For WooCommerce, you can use a hook to fix this flow:
This code manually adds the error notice to the WooCommerce session before redirecting back to the my-account page, ensuring the error displays as intended.add_action('woocommerce_login_failed', 'custom_login_failed_redirect', 10, 1); function custom_login_failed_redirect($username) { wc_add_notice(__('Invalid username or password.', 'woocommerce'), 'error'); wp_redirect(wc_get_page_permalink('myaccount')); exit; }
Pro Tip: Use your browser’s dev tools to inspect network requests when testing failed logins. Check the response headers and session data to confirm if errors are being stored in the session (where they belong) instead of being tacked onto the URL.
内容的提问来源于stack exchange,提问作者George Ntoum
相关产品推荐
相关产品推荐

