为何WordPress插件已配置名称仍提示‘无名称’错误?
WordPress插件仓库上传报错:已填写Plugin Name却提示“插件无名称”
问题详情
上传插件到WordPress插件仓库时收到错误提示:
Error: The plugin has no name. Add a Plugin Name: line to your main plugin file and upload the plugin again. For more information, please review our documentation on Plugin Headers.
但已经在主插件文件的头部注释中填写了Plugin Name字段,主文件代码如下:
<?php /** * Plugin Name: Wp Sitemap Disable * Plugin URI: https://github.com/ale0211/wp-disable-sitemap * Description: Lightweight Disable Sitemap * Version: 1.0.0 * Requires at least: 5.2 * Requires PHP: 7.2 * Author: Alessandro Amato * License: GPL v2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Update URI: https://github.com/ale0211/wp-disable-sitemap * Text Domain: Wp-Sitemap-Disable * Domain Path: /languages */ defined( 'ABSPATH' ) or die( 'Not allowed' ); function sitemap_off() { remove_action( 'init', 'wp_sitemaps_get_server' ); } add_action( 'init', 'sitemap_off');
解决办法
以下是几种可能的原因及对应修复步骤:
1. 文件编码问题(最常见)
WordPress插件仓库无法解析带BOM的UTF-8文件,会直接忽略头部注释:
- 用代码编辑器打开主插件文件,将编码切换为UTF-8无BOM格式后重新保存。
- 检查编辑器右下角的编码标识,确保不是“UTF-8 with BOM”。
2. 头部注释格式问题
注释结构需严格符合WordPress规范:
<?php之后必须直接紧跟/**,中间不能有空行或多余字符。- 每一行注释都要以
*开头(星号后必须有一个空格),建议将Text Domain行的多余空格调整为冒号后一个空格,避免解析异常。
3. 压缩包结构错误
WordPress要求主插件文件必须在压缩包根目录,不能嵌套在子文件夹中:
- 比如压缩包命名为
wp-sitemap-disable.zip,解压后应直接看到主PHP文件,而非先进入同名子文件夹才能找到文件。
4. 简化注释测试排查
暂时移除非必填字段,只保留核心必填项后重新上传:
<?php /** * Plugin Name: Wp Sitemap Disable * Version: 1.0.0 * Author: Alessandro Amato * License: GPL v2 or later */
如果能成功上传,再逐步添加其他字段,排查是否是某个字段的格式或内容导致解析失败。
内容的提问来源于stack exchange,提问作者Alessandro
相关产品推荐
相关产品推荐

