Show menu based on parent & ancestor

Work around. if (is_page( ‘pagename’ ) || in_array(“5”, $post->ancestors)) { wp_nav_menu( array( ‘container_class’ => ‘subnav’, ‘menu’ => ‘visit’ )); } 5 being the ID of the page in question. So while this is a bit more work, needing and if / if:else statement for each page, it will scale to allow as many child / … Read more

Find the Children of a Page then Echo it as a Bulleted List of Links (menu)

Well you just need to run a foreach loop over your $children but WordPress has a build in function for this already called wp list pages. For example: $children = wp_list_pages(‘title_li=&child_of=”.$post->ID.”&echo=1’); if ($children) echo ‘<ul>’ . $children . ‘</ul>’; There is a full reference and examples here: http://codex.wordpress.org/Function_Reference/wp_list_pages

Is it possible to pass variables from add_user_page?

The easiest and most clean way to solve that problem is using a specialised object. First create a class that can hold extra information: class Menu_Page { public $extra=””; public function render() { print $this->extra; } } Now create an object from that class … $page = new Menu_Page; $page->extra=”Hello World!”; … and register its … Read more

Check if menu id = $specific_id – then insert specific

Creating a custom Walker is a valid way to solve this, and is the first thing that crossed my mind, but it is not strictly necessary. It is possible to pull this off with filters, albeit by mildly abusing one of them 🙂 Proof of concept: function insert_image_wpse_130477($item_output) { remove_filter(‘walker_nav_menu_start_el’,’insert_image_wpse_130477′); $prepend = apply_filters(‘my_item_prepend’,”); return $prepend.$item_output; … Read more

Admin Panel – Custom Menu Sub-Item LINK

Insert the URL of the page as the $menu_slug argument. Also note that user levels are deprecated, you should pass a capability instead. function add_custom_link() { add_submenu_page( ‘edit.php?post_type=cpt_custom’, ”, ‘Pending Posts’, ‘edit_posts’, ‘edit.php?post_type=cpt_custom&post_status=pending’, ” ); } add_action(‘admin_menu’, ‘add_custom_link’);

How to construct a custom html for submenus

Okays.. i’ve solved this in my own way. i have added the following function in functions.php file class ik_walker extends Walker_Nav_Menu{ //start of the sub menu wrap function start_lvl(&$output, $depth) { $output .= ‘<div class=”dropdownContain”> <div class=”dropOut”> <div class=”triangle”></div> <ul>’; } //end of the sub menu wrap function end_lvl(&$output, $depth) { $output .= ‘ </ul> … Read more

Mark menu item as current-menu-item for category

I use this functions. First of all, you have to add some custom class to your menu item (allow class input in Screen options, it’s not visible by default). function mark_menu_item_as_active($classes, $item) { if( in_array(‘my-custom-class’,$classes) && ( is_category(‘my-category’) /* OR …*/ ) ) { $classes[] = ‘current-menu-item’; } return $classes; } add_filter(‘nav_menu_css_class’, ‘mark_menu_item_as_active’, 10, 2); … Read more