Tips

How To Fix The WordPress Error “The plugin does not have a valid header”

If you try to install a WordPress plugin and see the message “The plugin does not have a valid header” there might be an easy solution how to fix it.

Photo by transitpeople

I recently came across that error when trying to install and activate a plugin on my self-hosted WordPress sites. The message simply said: “The plugin does not have a valid header” Unfortunately, it was not really helpful to debug the problem. What made it even more mystifying was the fact that the plugin could still be activated from the list of plugins, but not directly after installation.

This problem is often caused by a wrong folder structure in the plugin – for example if the plugin’s main file is placed in a second level under the “wp-content/plugins/” directory:

wp-content/plugins/my-plugin/my-plugin/ (files here)

In that case it helps to move everything up by one level:

wp-content/plugins/my-plugin/ (files here)

That, however, was not the case here. After some searching I found that the headers of some PHP files hidden in the sub-folders of the plugin looked similar to the mandatory header of plugin main files:

/*
Plugin Name: ...
Plugin URI: ...
Author: ...
...

WordPress seemed to assume that one of those files was the actual main plugin file.

I fixed the issue by going through all files and changing the format of the headers to something that wouldn’t confuse the installer. Afterwards, the installation needed to be repeated from the start with the correct files.

Photo by transitpeople

Let an expert fix it

3 thoughts on “How To Fix The WordPress Error “The plugin does not have a valid header”

  • Abu

    Indeed this was actually what happened to my plugin, I had to remove the individual headers from the files. Thank you.

  • Patrick Mineo

    Can you offer some insight into exactly how you removed the individual headers from the files. Much appreciated in advance!

    • Christoph

      You will need to edit the files where these headers occur with a text editor that lets you edit code without adding any formatting, for example with one of those: https://en.wikipedia.org/wiki/List_of_PHP_editors Just unzip the plugin’s ZIP file, edit the files and zip them again, then install that new ZIP file. It’s a bit tricky if you are not used to edit code, so in that case it might be easier and safer to contact the plugin author.

      You may also try the Plugins -> Editor page in the WordPress back end, select the plugin on the right hand side and then go through all files ending on “.php”, but you risk to make your site inaccessible if you produce an error in the code. See https://codex.wordpress.org/Editing_Files

      What exactly to edit: I don’t remember what I actually did one year ago, but it should be OK to remove inside the comments /* … */ some or all of:
      Plugin Name: …
      Plugin URI: …
      Author: ..
      or to change the key words (“Plugin Name:” becomes “Plugin Name B:” or similar). That’s probably safer, since you don’t risk to break the comments (/* …*/). Just make sure you don’t touch the headers of the main plugin PHP file in the main directory. The main file is usually a file with an identical name as that plugin’s directory with appended “.php”, something like “example-plugin/example-plugin.php”.

Comments are closed.