Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Created November 29, 2016 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablo-sg-pacheco/30b94a9dbd93d46ad09b9bfd785ddc00 to your computer and use it in GitHub Desktop.
Save pablo-sg-pacheco/30b94a9dbd93d46ad09b9bfd785ddc00 to your computer and use it in GitHub Desktop.
Converte o menu para o contact details
<?php
add_filter( 'wp_get_nav_menu_items', function($items, $menu, $args){
if($menu->name!='Rodapé-3'){
return $items;
}
if(is_admin()){
return $items;
}
$contactDetails = get_option('contact');
foreach ( $items as $item ) {
foreach ( $contactDetails as $key => $detail ) {
$originalDetail = $detail;
$detail = preg_replace('/http:\/\/.*\//', '', $detail);
if($item->title=='{{instagram}}'){
$detail='@'.$detail;
$item->url = $originalDetail;
$item->target='_blank';
}
$item->title = str_replace('{{'.$key.'}}', $detail, $item->title);
}
}
return $items;
}, null, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment