Fatal Error: Cannot Redeclare file_get_html (Previously Declared in WordPress)
While WordPress and its plug-ins normally hide their inner PHP code from you, an occasional error message can result if plug-ins or themes aren't properly coded. One common error message is "Fatal error: Cannot redeclare file_get_html()," accompanied by the statement, "(Previously declared in [location])." The good news is that the information in the error message can help you solve the problem.
-
About the Error
-
WordPress as well as its themes and plug-ins are actually scripts written in PHP code and executed by the Web server. That code can access PHP functions by using an "require" or "require_once" statement. However, if a script tries to require a function that is already in use, PHP won't allow the script to continue and generates an error message stating that it can't re-declare, or reload, the function because it's already loaded. A fatal error disables only the script that's being loaded and usually won't prevent WordPress from displaying pages.
About File_get_html
-
The "file_get_html" function instructs PHP to load an HTML parser, which enables manipulation of HTML code within WordPress. This parser can be used in a wide variety of ways, from translating your WordPress blog posts into another language to fetching information from another site. Because this function is so versatile, a large number of plug-ins require it. Some plug-in developers attempt to load this function without also writing code to ensure the function isn't already loaded, which can cause an error.
-
Disable or Update Plug-in
-
The fastest way to solve a problem with a WordPress plug-in is to disable the plug-in. In this case, you can either disable the plug-in you activated just before the error occurred or the plug-in mentioned in the "previously declared in" portion of the error message. You can also check to see if there's an updated version of either plug-in that might fix the problem. If no update is available, contact the plug-in developer to see if they're aware of the issue. You can find the developer's website on the Plug-ins page in your WordPress site's administration area and clicking on "Visit plug-in site" under the name of the plug-in.
Reload Plug-ins
-
Another solution that has worked for others is disabling both plug-ins mentioned in the error message and then re-enabling them in reverse order. However, this will solve the problem only if one of the plug-ins is correctly written. If the problem persists you'll have to look for an update to one or both of the plug-ins or fix the code yourself.
Edit PHP Code
-
If you're comfortable editing PHP code, you may solve the problem by wrapping the function in a conditional statement so that the plug-in will require the function only if it isn't loaded. To add the statement, use a File Transfer Protocol program to find the second file specified in the error message, not the first file listed within the parentheses. Open the file in a text editor and add the following text just above the line beginning with "function file_get_html": if(!function_exists('file_get_html')){. Then look for the first closing brace, "}," to appear after that text, and on a new line below it type another closing brace. Save the file and upload it with your FTP program, replacing the old version. You can then try reloading the plug-in or viewing the page where the error occurred.
-
- Photo Credit Thinkstock/Comstock/Getty Images