You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决WordPress WooCommerce我的账户页面无法加载不同页眉问题

Fix: Load Custom CSS/JS via Template Part Instead of Default Header on WooCommerce Account Pages

Hey there! I’ve run into this exact issue before with WooCommerce’s account pages (login, forgot password, register) where the default header loads all sorts of unnecessary assets, and we just want a lean setup with only the required CSS and JS. Here’s how to fix it step by step:

Step 1: Override WooCommerce Account Templates

WooCommerce lets you override its core templates in your theme, which is the safest way to make changes without touching plugin files.

  • Navigate to wp-content/plugins/woocommerce/templates/myaccount/
  • Copy the following files to your theme’s woocommerce/myaccount/ directory (create the folder if it doesn’t exist):
    • form-login.php (login page)
    • form-lost-password.php (forgot password page)
    • form-register.php (register page)

Step 2: Remove Default Header Call from Templates

Open each copied file and look for the line that loads the header—it’ll usually be something like:

get_header( 'shop' );

Or just get_header(); if your theme doesn’t use a custom shop header. Delete this line entirely.

Step 3: Create a Custom Template Part for Assets

Now we’ll make a template part that only loads the CSS and JS your account pages need.

  • In your theme directory, create a new folder called template-parts (if it doesn’t exist)
  • Inside that folder, create a file named account-assets.php
  • Add your asset enqueues or inline styles/scripts to this file. For example:
<?php
// Enqueue custom account page styles
wp_enqueue_style( 'account-page-styles', get_stylesheet_directory_uri() . '/css/account-styles.css', array(), wp_get_theme()->get('Version') );

// Enqueue custom account page scripts (depends on jQuery)
wp_enqueue_script( 'account-page-scripts', get_stylesheet_directory_uri() . '/js/account-scripts.js', array('jquery'), wp_get_theme()->get('Version'), true );
?>

If you need inline styles or scripts, you can add them directly in this file too, wrapped in <style> or <script> tags.

Step 4: Load the Custom Template Part in Account Pages

Go back to each modified WooCommerce account template (the ones you copied to your theme) and add this line at the top, where the old get_header() call used to be:

get_template_part( 'template-parts/account-assets' );

If the default footer is also loading unnecessary assets, you can repeat the process: remove get_footer(); from the account templates and create a lean footer template part if needed.

Pro Tips

  • Use a Child Theme: Always make these changes in a child theme so your edits don’t get overwritten when your parent theme updates.
  • Clear Cache: After making changes, clear your WordPress cache (and any CDN/browser cache) to see the updates take effect.
  • Test Thoroughly: Make sure all account page functions (login, password reset, registration) still work correctly after the changes.

内容的提问来源于stack exchange,提问作者Teja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:59:42