Skip to content

Instantly share code, notes, and snippets.

@claudioweb
Last active July 6, 2017 22:48
Show Gist options
  • Save claudioweb/aa79287d1dd920da904a496eb2d1e6bf to your computer and use it in GitHub Desktop.
Save claudioweb/aa79287d1dd920da904a496eb2d1e6bf to your computer and use it in GitHub Desktop.
Cadastrar menus como exemplo ou como padrão do tema
<?php
// Grupos de Menu
$arr_menus = array('Redes sociais');
public function action_create_item_menu($arr_menus){
foreach ($arr_menus as $key => $menu) {
// Verifica se o menu existe
$menu_exists = wp_get_nav_menu_object( $menu );
// Cria o menu e obtem seu ID
$menu_id = wp_create_nav_menu($menu);
/* Cria uma opção do menu.
(replicar para obter outras opções) */
// Verifica se ja existe a opção
$menus_registred = wp_get_nav_menus();
foreach($menus_registred as $registred_m){
if(!in_array($registred_m->name,$arr_menus)){
$args['facebook']['menu-item-title'] = 'Facebook';
$args['facebook']['menu-item-classes'] = 'fa fa-facebook';
$args['facebook']['menu-item-url'] = '';
$args['facebook']['menu-item-status'] = 'publish';
$args['facebook']['menu-item-target'] = '_blank';
// Criando opção no menu
wp_update_nav_menu_item($menu_id, 0, $args);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment