Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at

RSS Latest posts from my personal blog

Most viewed posts

Subscribe to RSS feed

Change WordPress plugin load order

Stanislav KhromovStanislav Khromov

Changing the plugin load order should only be done as a last-ditch effort. If you want to interface with other plugins, it can most often be solved by hooking on plugins_loaded before running your code. That will make sure that all plugins have been loaded before your code is executed.

This snippet will reorder the plugin load list to load your plugin first.

add_action( 'activated_plugin', 'my_plugin_load_first' );
function my_plugin_load_first()
    $path = str_replace( WP_PLUGIN_DIR . '/', '', __FILE__ );
    if ( $plugins = get_option( 'active_plugins' ) ) {
        if ( $key = array_search( $path, $plugins ) ) {
            array_splice( $plugins, $key, 1 );
            array_unshift( $plugins, $path );
            update_option( 'active_plugins', $plugins );

Full article here


Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
Twitter Profile
Visit my other blog

Comments 0
There are currently no comments.