Advertisement
fauzanjeg

Select Menu for Specific Posts

Nov 1st, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. /* Select Menu for Specific Posts */
  2. function menu_for_spesific_post( $args ) {
  3.     $slug_post = get_post_field( 'post_name', get_the_ID() );
  4.     $list_post = array( 'hello-world', 'baru', 'slug-2', 'slug-3' ); /* List Posts by Slug */
  5.     if ( in_array( $slug_post, $list_post ) ) {
  6.         /* If Main Menu (navigation) */
  7.         if ( 'navigation' === $args['theme_location'] ) {
  8.             /* Get Menu ID by Menu Name */
  9.             $term = get_term_by('name', 'Footer Navigation', 'nav_menu');
  10.             $menu_id = $term->term_id;
  11.  
  12.             $args['menu'] = $menu_id;
  13.         }
  14.     }
  15.  
  16.     return $args;
  17. }
  18. // add_filter( 'wp_nav_menu_args', 'menu_for_spesific_post' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement