Using WordPress ‘media_library_infinite_scrolling’ PHP filter

The media_library_infinite_scrolling WordPress PHP filter enables or disables infinite scrolling in the Media Library grid. By default, infinite scrolling is disabled.

Usage

add_filter('media_library_infinite_scrolling', 'your_function_name');
function your_function_name($infinite) {
    // your custom code here
    return $infinite;
}

Parameters

  • $infinite (bool): Whether the Media Library grid has infinite scrolling.

More information

See WordPress Developer Resources: media_library_infinite_scrolling

Examples

Enable Infinite Scrolling

Enable infinite scrolling for the Media Library grid.

add_filter('media_library_infinite_scrolling', 'enable_infinite_scrolling');
function enable_infinite_scrolling($infinite) {
    $infinite = true;
    return $infinite;
}

Disable Infinite Scrolling

Explicitly disable infinite scrolling for the Media Library grid.

add_filter('media_library_infinite_scrolling', 'disable_infinite_scrolling');
function disable_infinite_scrolling($infinite) {
    $infinite = false;
    return $infinite;
}

Enable Infinite Scrolling for Administrators Only

Enable infinite scrolling for administrators and disable it for other user roles.

add_filter('media_library_infinite_scrolling', 'admin_infinite_scrolling');
function admin_infinite_scrolling($infinite) {
    if (current_user_can('manage_options')) {
        $infinite = true;
    } else {
        $infinite = false;
    }
    return $infinite;
}

Enable Infinite Scrolling on a Custom Post Type

Enable infinite scrolling for the Media Library grid when viewing a specific custom post type.

add_filter('media_library_infinite_scrolling', 'cpt_infinite_scrolling');
function cpt_infinite_scrolling($infinite) {
    global $post;
    if ($post->post_type == 'your_custom_post_type') {
        $infinite = true;
    } else {
        $infinite = false;
    }
    return $infinite;
}

Enable Infinite Scrolling Conditionally

Enable infinite scrolling for the Media Library grid based on a custom condition.

add_filter('media_library_infinite_scrolling', 'conditional_infinite_scrolling');
function conditional_infinite_scrolling($infinite) {
    // Define your custom condition here
    $custom_condition = true;

    if ($custom_condition) {
        $infinite = true;
    } else {
        $infinite = false;
    }
    return $infinite;
}