This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
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.
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!
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.