最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Remove "Filter" Button on All Posts in wp-admin

programmeradmin5浏览0评论

I've used code to remove other elements on the bar where the "Filter" button is displayed, but I can't find a way to (ideally) disable or (less ideally) hide this button.

I've used code to remove other elements on the bar where the "Filter" button is displayed, but I can't find a way to (ideally) disable or (less ideally) hide this button.

Share Improve this question asked Jul 18, 2021 at 6:26 fakeguybrushthreepwoodfakeguybrushthreepwood 2111 gold badge5 silver badges15 bronze badges 3
  • You can hide it visually via CSS, e.g. #posts-filter .tablenav .actions { display: none; }, or use JS to remove the "actions" div or just that button. But are you sure you want to disable the ability to filter the posts via that div/button? – Sally CJ Commented Jul 18, 2021 at 7:00
  • Looking at the wordpress repo there doesn't seem to be an easy way to remove that button without editing core files, no action/filter is available for you to hook into. Seems like the best way woulf be with css, as @SallyCJ suggested. – Buttered_Toast Commented Jul 18, 2021 at 7:04
  • @SallyCJ yes, actually I want to understand how it works on Posts first and then do it on a custom post type that has no need for such functionality. – fakeguybrushthreepwood Commented Jul 18, 2021 at 7:22
Add a comment  | 

1 Answer 1

Reset to default 0

There isn't a filter or an action in order to prevent this BUT

Wordpress adds the post-type slug of the current page post type to the classes in body tag. Also the slug of the page, in your case .edit-php

If you want to do it with css (replace {your_post_type} with your post type)

body.post-type-{your_post_type}.edit-php #post-query-submit{
    display: none!important;
}

ie: for page post type:

body.post-type-page.edit-php #post-query-submit{
    display: none!important;
}

If you want to do it in javascript:

add_action( 'admin_footer', function(){
    echo <<<EOF
<script>
    jQuery(document).ready(function(){
      jQuery('body.post-type-{your_post_type}.edit-php #post-query-submit').remove();
    });
</script>
EOF;

} );

Remember to replace {your_post_type} with the slug of your custom post type.

发布评论

评论列表(0)

  1. 暂无评论