How to have wordpress load plugins in a specific order

Apr 19th, 2011 | By | Category: Internet

Or more specifically in this example how to get wordpress to load a specific  plugin before all others.  By default wordpress will load your plugins in alphabetical order as for the most part 99.99% of people could care less and are unaffected by plugin execution order.  However for that .01% of us(don’t you feel special now?) it can cause some serious havoc to have one plugin do it’s thang before another.  In order to give one plugin priority and load first you need to stick the following code in that plugin’s main php file:


function this_plugin_first() {
// ensure path to this file is via main wp plugin path
$wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", __FILE__);
$this_plugin = plugin_basename(trim($wp_path_to_this_file));
$active_plugins = get_option('active_plugins');
$this_plugin_key = array_search($this_plugin, $active_plugins);
if ($this_plugin_key) { // if it's 0 it's the first plugin already, no need to continue
array_splice($active_plugins, $this_plugin_key, 1);
array_unshift($active_plugins, $this_plugin);
update_option('active_plugins', $active_plugins);
add_action("activated_plugin", "this_plugin_first");

Many thanks to jsdalton in this thread: for posting up the solution and make sure you check out that thread for more discussions on the topic


Alternatively there is a handy little plugin that helps you do this and more found here:

Tags: , , , , ,

Leave a Comment