The disable_formats_dropdown WordPress PHP filter allows you to control the visibility of the ‘Formats’ drop-down menu in the post list table.
Usage
add_filter('disable_formats_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 drop-down. Default isfalse.$post_type(string) – The post type slug.
More information
See WordPress Developer Resources: disable_formats_dropdown
Examples
Disable ‘Formats’ drop-down for all post types
Disables the ‘Formats’ drop-down for all post types.
add_filter('disable_formats_dropdown', 'disable_all_formats_dropdown', 10, 2);
function disable_all_formats_dropdown($disable, $post_type) {
return true;
}
Disable ‘Formats’ drop-down for a specific post type
Disables the ‘Formats’ drop-down for the ‘product’ post type.
add_filter('disable_formats_dropdown', 'disable_formats_dropdown_for_product', 10, 2);
function disable_formats_dropdown_for_product($disable, $post_type) {
if ($post_type == 'product') {
return true;
}
return $disable;
}
Enable ‘Formats’ drop-down for a specific post type
Enables the ‘Formats’ drop-down for the ‘news’ post type, even if it is disabled globally.
add_filter('disable_formats_dropdown', 'enable_formats_dropdown_for_news', 10, 2);
function enable_formats_dropdown_for_news($disable, $post_type) {
if ($post_type == 'news') {
return false;
}
return $disable;
}
Disable ‘Formats’ drop-down based on user role
Disables the ‘Formats’ drop-down for users with the ‘subscriber’ role.
add_filter('disable_formats_dropdown', 'disable_formats_dropdown_for_subscribers', 10, 2);
function disable_formats_dropdown_for_subscribers($disable, $post_type) {
if (current_user_can('subscriber')) {
return true;
}
return $disable;
}
Enable ‘Formats’ drop-down based on user capability
Enables the ‘Formats’ drop-down for users with the ‘manage_options’ capability.
add_filter('disable_formats_dropdown', 'enable_formats_dropdown_for_managers', 10, 2);
function enable_formats_dropdown_for_managers($disable, $post_type) {
if (current_user_can('manage_options')) {
return false;
}
return $disable;
}