Halloween Sale 15% off Ends in See the plans
PHP

List Active Plugins First on the Plugins Screen

Moves active plugins to the top of the Plugins screen, followed by the inactive ones, keeping alphabetical order inside each group.

Don’t have WPIDE yet? Install it on your site

Code

// Reorders the rows of the Plugins screen so active plugins come first. Alphabetical order is kept inside each group.
add_action( 'admin_footer-plugins.php', function () {
    ?>
    <script>
    ( function () {
        var list = document.getElementById( 'the-list' );
        if ( ! list ) {
            return;
        }

        // A plugin row can be followed by its update notice and rows added by other plugins.
        var groups = [];
        var current = null;
        Array.prototype.slice.call( list.children ).forEach( function ( row ) {
            if ( row.hasAttribute( 'data-plugin' ) && ! row.classList.contains( 'plugin-update-tr' ) ) {
                current = { active: row.classList.contains( 'active' ), rows: [] };
                groups.push( current );
            }
            if ( current ) {
                current.rows.push( row );
            }
        } );

        var ordered = groups.filter( function ( group ) { return group.active; } )
            .concat( groups.filter( function ( group ) { return ! group.active; } ) );

        ordered.forEach( function ( group ) {
            group.rows.forEach( function ( row ) {
                list.appendChild( row );
            } );
        } );
    } )();
    </script>
    <?php
} );

Notes

The rows are reordered in the browser as the screen loads. Search, filters and bulk actions work as usual.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.