Tips and tricks

How to assign a menu to a wordpress theme location from php

This is the code

$locations = get_theme_mod( 'nav_menu_locations' );

if(!empty($locations))
{
   foreach($locations as $locationId => $menuValue)
   {


      if($locationId=='primary'){

         if(isset($menu_id))
         {
            $locations[$locationId] = $menu_id;
            set_theme_mod('nav_menu_locations', $locations);
         }
      }

   }

}

replace ‘primary’ with the location of your theme, for the menu.

Leave a comment

Your email address will not be published

{"type":"main_options","images_arr":"'#ffffff'","bg_slideshow_time":"0","site_url":"https:\/\/digitalzoomstudio.net","theme_url":"https:\/\/digitalzoomstudio.net\/wp-content\/themes\/qucreative\/","is_customize_preview":"off","gallery_w_thumbs_autoplay_videos":"off","base_url":"https:\/\/digitalzoomstudio.net"}