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.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.