Advertisement
GochiSiyan

new code

May 5th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. add_filter( 'theme_mod_nav_menu_locations', function ( $menu ) {
  2. if ( is_category() || is_singular( 'post' ) ) {
  3. if ( is_category() ) {
  4. $category = [get_queried_object()];
  5. } else {
  6. $category = get_the_category();
  7. }
  8. $data = [];
  9. $cats = [0,0,0,0];//list of category id to change
  10. jnews_recursive_category(get_categories([
  11. 'include' => $cats,
  12. ]), $data);
  13.  
  14. if ( array_uintersect( $category, $data, function ( $a, $b ) {
  15. if ( $a->term_id === $b->term_id ) {
  16. return 0;
  17. }
  18. if ( $a->term_id > $b->term_id ) return 1;
  19. return -1;
  20. } ) ) {
  21. $menu = is_array( $menu ) ? $menu : array();
  22. $menu['navigation'] = 0;//the menu id you wish to assign to the category.
  23. }
  24. }
  25. return $menu;
  26. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement