Code snippet: Change the Page Length options in Document Library Pro
Please note: This article is aimed at developers. We have provided an article on how to add code snippets. If you're not comfortable using them, then you can use our plugin customization service.
Document Library Pro lets you set the number of documents per page and choose where the documents-per-page selector appears. The selector normally includes 10, 25, 50 and 100, together with your selected documents-per-page value if it is different. Some configurations also include an All option.
Use the following code snippet to change the choices or remove the All option. The snippet supports the current frontend in table and grid layouts, plus the legacy jQuery DataTables frontend in table layout.
Code snippet
Add this PHP code to your theme or child theme, or with a code snippets plugin:
add_filter( 'document_library_pro_dataviews_config', 'barn2_dlp_change_page_length_options' );
function barn2_dlp_change_page_length_options( $config ) {
$config['rowsPerPageOptions'] = [ 10, 20, 30 ];
return $config;
}
add_filter( 'document_library_pro_data_config', 'barn2_dlp_change_legacy_page_length_options' );
function barn2_dlp_change_legacy_page_length_options( $config ) {
$page_lengths = [ 10, 20, 30 ];
$config['lengthMenu'] = [ $page_lengths, $page_lengths ];
return $config;
}
This example changes the dropdown to 10, 20 and 30 documents per page. It does not include the All option.
Make sure the library's Documents per page setting matches one of the values in the snippet, or add that value to both arrays.
If you have enabled the legacy frontend and use the grid layout, these filters do not change its page-length choices. Switch off the legacy frontend at Documents → Settings → Advanced to use the current frontend.
Including the All option
If you want to keep the All option while changing the other choices, use this version instead:
add_filter( 'document_library_pro_dataviews_config', 'barn2_dlp_change_page_length_options' );
function barn2_dlp_change_page_length_options( $config ) {
$config['rowsPerPageOptions'] = [ 10, 20, 30, -1 ];
return $config;
}
add_filter( 'document_library_pro_data_config', 'barn2_dlp_change_legacy_page_length_options' );
function barn2_dlp_change_legacy_page_length_options( $config ) {
$config['lengthMenu'] = [
[ 10, 20, 30, -1 ],
[ 10, 20, 30, __( 'All', 'document-library-pro' ) ],
];
return $config;
}
The value -1 tells Document Library Pro to display every document in the library. Avoid offering All on a very large library because loading every document at once can affect performance.