Using WordPress ‘disable_categories_dropdown’ PHP filter

The disable_categories_dropdown WordPress PHP filter allows you to control the visibility of the ‘Categories’ drop-down in the post list table.

Usage

add_filter( 'disable_categories_dropdown', 'your_custom_function', 10, 2 );

function your_custom_function( $disable, $post_type ) {
    // your custom code here
    return $disable;
}

Parameters

  • $disable (bool) – Whether to disable the categories drop-down. Default false.
  • $post_type (string) – Post type slug.

More information

See WordPress Developer Resources: disable_categories_dropdown

Examples

Disable categories drop-down for all post types

Disables the categories drop-down for all post types.

add_filter( 'disable_categories_dropdown', '__return_true' );

Disable categories drop-down for a specific post type

Disables the categories drop-down for a custom post type called ‘product’.

add_filter( 'disable_categories_dropdown', 'disable_dropdown_for_product', 10, 2 );

function disable_dropdown_for_product( $disable, $post_type ) {
    if ( 'product' === $post_type ) {
        return true;
    }
    return $disable;
}

Enable categories drop-down for a specific post type

Enables the categories drop-down for a custom post type called ‘event’ while disabling it for other post types.

add_filter( 'disable_categories_dropdown', 'enable_dropdown_for_event', 10, 2 );

function enable_dropdown_for_event( $disable, $post_type ) {
    if ( 'event' === $post_type ) {
        return false;
    }
    return true;
}

Disable categories drop-down for multiple post types

Disables the categories drop-down for custom post types ‘product’ and ‘review’.

add_filter( 'disable_categories_dropdown', 'disable_dropdown_for_multiple', 10, 2 );

function disable_dropdown_for_multiple( $disable, $post_type ) {
    $disabled_post_types = array( 'product', 'review' );

    if ( in_array( $post_type, $disabled_post_types ) ) {
        return true;
    }
    return $disable;
}

Conditionally disable categories drop-down

Disables the categories drop-down based on user role.

add_filter( 'disable_categories_dropdown', 'disable_dropdown_for_author', 10, 2 );

function disable_dropdown_for_author( $disable, $post_type ) {
    $current_user = wp_get_current_user();

    if ( in_array( 'author', $current_user->roles ) ) {
        return true;
    }
    return $disable;
}