Advertisement
GochiSiyan

category and post custom menu

May 3rd, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 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. if ( array_intersect( $category, $data ) ) {
  14. $menu = is_array( $menu ) ? $menu : array();
  15. $menu['navigation'] = 0;//the menu id you wish to assign to the category.
  16. }
  17. }
  18. return $menu;
  19. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement