December 22nd in Wordpress by pbu .

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:

Share and Enjoy:
  • del.icio.us
  • digg
  • StumbleUpon
  • Technorati
  • DZone
  • Facebook
  • FriendFeed
  • Reddit
  • RSS
  • Twitter

2 Comments

  • James Andrews
    December 22, 2009
    • pbu
      December 23, 2009

Leave A Comment.