WordPress子主题安装报错:父子主题均被识别为子主题
It sounds like the issue is rooted in incorrect header declarations in either your parent or child theme's style.css file. Here's how to troubleshoot and fix it:
1. Check the Parent Theme's style.css (Critical!)
Parent themes should never include a Template: line in their header—this is exclusive to child themes. If your parent theme has this line, WordPress will mistakenly flag it as a child theme.
- Navigate to
/wp-content/themes/consulting/(your parent theme folder) and openstyle.css. - Look for any line starting with
Template:. If you find it, delete it immediately. - A correct parent theme header should look like this:
/* Theme Name: consulting Theme URI: http://example.com/consulting/ Description: A professional consulting theme Author: John Doe Author URI: http://example.com Version: 1.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Text Domain: consulting */
2. Validate the Child Theme's style.css Header
Your child theme's header must have a Template: line that exactly matches the parent theme's folder name (this is case-sensitive, especially on Linux servers).
- Open your child theme's
style.cssfile. - Ensure the
Template:value matches the parent's folder name (e.g., if parent is in/consulting/, useTemplate: consulting). - Example of a correct child theme header:
/* Theme Name: consulting Child Theme URI: http://example.com/consulting-child/ Description: Custom child theme for consulting Author: John Doe Author URI: http://example.com Template: consulting Version: 1.0.0 Text Domain: consulting-child */ - Common mistakes here: Typos in the folder name, using the theme's display name instead of the folder name, or incorrect capitalization (e.g.,
Consultinginstead ofconsulting).
3. Verify Folder Names
Double-check that your parent theme's folder name is exactly what you specified in the child's Template line. For example, if the parent folder is named consulting-v2, your child's Template line must be Template: consulting-v2.
4. Apply Changes and Test
- Save all edits to both
style.cssfiles. - Go to your WordPress Dashboard > Appearance > Themes. You should now see the parent theme as a standalone theme, and the child theme marked as a child of "consulting".
- If the issue persists, clear any caching plugins you're using and refresh the themes page.
This should resolve the problem where both themes are being recognized as child themes. The most common culprit is accidentally adding a Template: line to the parent theme when copying code from the Codex.
内容的提问来源于stack exchange,提问作者user9340719

