Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bappi-d-great/26808240df88dd1fc3fe to your computer and use it in GitHub Desktop.
Save bappi-d-great/26808240df88dd1fc3fe to your computer and use it in GitHub Desktop.
How to load a wordpress plugin at very last - change plugin order to load last
<?php
/*
*
* Use the code at the beginning of a plugin that you want to be laoded at last
*
*/
function this_plugin_last() {
$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);
array_splice($active_plugins, $this_plugin_key, 1);
array_push($active_plugins, $this_plugin);
update_option('active_plugins', $active_plugins);
}
add_action("activated_plugin", "this_plugin_last");
@faridfox
Copy link

Is it possible to add it to functions.php and use preg_replace to plugin name? to avoid plugin updates override.
thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment