0

I try to use a filter to remove some pages from Widget Pages but it seems not to be working. What I am doing wrong?

  add_filter( 'widget_pages_args', 'custom_list_pages_filter', 10, 1 );

  function custom_list_pages_filter($args) {
     error_log(); 
      $remove = array(2); // or could be array(1,2,3,4)
      $args['exclude'] = implode( ',', $remove );
      return $args;
  } 
3
  • Are you using the legacy pages Widget, or are you using the Block? Oct 5, 2022 at 15:18
  • Its says Page List. How can I tell the difference, please? It's WP 6.0.2 with a Twenty Twenty theme child. Oct 6, 2022 at 7:28
  • Finally I understand this is a block!, So the filter does not apply. Files are in /wp-includes/blocks/page-list/ and in the file block.json I found the title and description. The code is in file /wp-includes/blocks/page-list.php and there is no filter there: $all_pages = get_pages( array( 'sort_column' => 'menu_order,post_title', 'order' => 'asc', ) ); Oct 6, 2022 at 8:21

1 Answer 1

0

Now, that I have noticed Page List is a block widget. I think I have two solutions: a) Revert to classic widgets with the Classic Widgets Plugin and use the filter b) Create a new block and filter pages it my way. This one I think is much harder. Thanks to @jacob-peattie for the insight.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.