Exciting News! Flipper Code is now WePlugins! Same commitment to WordPress Development excellence, brand new identity.

How to use edit_categories_per_page filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
May 23, 2023
5 minutes read

When working with WordPress, it’s super important to know how to customize the way your site functions. One of the coolest things you can do is use hooks to change or extend the core functionalities without touching the core files. Today, let’s talk about the edit_categories_per_page filter hook. This hook is all about controlling how many categories you see on your Categories list table page in the WordPress admin area. Pretty neat, right?

Example 1: Modify Categories Per Page

Let’s say you want to adjust the number of categories displayed per page. Here’s how you can do it:

    function weplugins_modify_edit_categories_per_page_defaults($tags_per_page) { 
        // Update the $tags_per_page variable according to your website requirements
        return $tags_per_page; 
    }
    // add the filter
    add_filter("edit_categories_per_page", "weplugins_modify_edit_categories_per_page_defaults", 10, 1);
    

Example 2: Conditional Modification

Maybe you want to change the number of categories displayed only for specific users. Here’s how you can conditionally modify it:

    function weplugins_conditional_edit_categories_per_page($tags_per_page) {
        if (current_user_can('administrator')) {
            $tags_per_page = 30; // Display 30 categories for admins
        }
        return $tags_per_page;
    }
    add_filter("edit_categories_per_page", "weplugins_conditional_edit_categories_per_page", 10, 1);
    

Example 3: Removing the Filter

In case you need to remove the filter, here’s the way to do it:

    remove_filter("edit_categories_per_page", "weplugins_modify_edit_categories_per_page_defaults", 10, 1);
    

Make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

Access Premium WordPress Plugins

Contact Us

If you’re having any trouble using this hook or need a bit of customization, don’t hesitate to contact us. Our team at WePlugins is here to help!

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.