Fix ->Wordpres plugin could not be activated fatal error cannot redeclare!
I have seen this error thrown up many many times while activating a wordpress plugin and the
Plugin could not be activated because it triggered a fatal error.
Fatal error: Cannot redeclare similar_posts() (previously declared in /home/pbu/public_html/blog/wp-content/plugins/xxxx/xxxx:45) in /home/pbu/public_html/blog/wp-content/plugins/x/xxxx.php on line 46
The main reason why the plugin could not be activated is because there must be either a plugin clash using same function or a wordpress theme calling the plugin function using the same name ie. double declaration.
Placing the plugin code in your wordpress theme file like this is the root cause for fatal errors in blogs and plugin activation.
If the plugin gets deactivated or not present, it would simply crash your blog with fatal error.
The safe way of placing plugin code in your theme files is first to check whether the function exists, if so call it.
<?php
if (function_exists(’similar_posts’))
{
similar_posts();
}
?>
In the above method, even if the plugin is not installed, it wouldnt crash your blog!
To fix:
1. Deactivate the plugin first.
2. Look in your wordpress theme files (single.php, archive.php, index.php) including widgets for a function call with same name (usually redeclaration), just remove or comment it out.
3. Now activate the plugin and see if it works.
Similar Posts:
- Fix -> Fatal error – Call to undefined function: screen_icon() in WP-Pagenavi Plugin
- How to post source code in Wordpress posts?
- 10 Best Wordpress PLUGINS You Never want to MISS!
- Which wordpress plugins to show related posts!
- Tutorial: How to write a Wordpress Plugin?
- 3 Must Do Things for Wordpress Blog Starters
- Affiliate Hide v1.0 – Free Wordpress plugin to Hide & Redirect Affiliate Links
- Best affiliate plugins for Wordpress!
- Wordpress offline editors for blogging!
- Best & Useful Wordpress Plugins For Blogs


December 22, 2009
The problem with that though is it still doesn’t fix the problem. If the function exists and has different attributes, then you may be calling the wrong function and then things are not going to be happy. A better option is when writing a them is to make sure all your functions carry a namespace that won’t be common for example
myplugin_similar_posts()
unless your plugin has the same name as another plugin, then your functions shouldn’t collide.
December 23, 2009
Cant agree more! Like you said the functions should be uniquely chosen to avoid collision.