Advertisement
IdeaG

Editing Wordpress menu items

Mar 19th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. // WordPress snippet to alter menu items - add something to title or etc.
  2. // (c) Stephen Harris - http://wordpress.stackexchange.com/questions/40226/adding-custom-text-in-items-titles-from-wp-nav-menu
  3. add_filter( 'wp_setup_nav_menu_item','my_item_setup' );
  4. function my_item_setup($item) {
  5.     //Use the following to conduct logic;
  6.     $object_id = (int) $item->object_id; //object ID.
  7.     $object_type = $item->type; //E.g. 'post_type'
  8.     $object_type_label = $item->type_label; //E.g. 'post' or 'page';
  9.  
  10.     //You could, optionally add classes to the menu item.
  11.     $item_class = $item->classes;
  12.  
  13.     //Make sure $item_class is an array.
  14.     //Alter the class:
  15.     $item->classes= $item_class;
  16.  
  17.     //Alter the title:
  18.     $pack_meta_value = get_post_meta($object_id, 'test', true );
  19.      if($pack_meta_value ){
  20.          $item->title = $item->title.'<span>' . $pack_meta_value . '</span>';
  21.      }
  22.  
  23.     return $item;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement