• Basically, wp_page_menu doesn’t allow you to replace the container. God knows why, but it doesn’t. I’m terrible at PHP, but I’ve managed to do so with a very basic function:

    function replace_menu_div( $newel ) {
    	$html4nav = array();
    	$html4nav[0] = '/<div class="menu">/';
    	$html4nav[1] = '/<\/div>/';
    	$html5nav = array();
    	$html5nav[0] = '<nav class="menu">';
    	$html5nav[1] = '</nav>';
    	ksort($html4nav);
    	ksort($html5nav);
    	return preg_replace($html4nav, $html5nav, $newel, 1);
    	}
    add_filter('wp_page_menu','replace_menu_div');

    However, as you can see, this little function won’t take in new classes. It simply replaces the default div with a “menu” class with a nav and a “menu” class as well.

    Help? Suggestions?

Viewing 3 replies - 1 through 3 (of 3 total)
  • What do you want it to do? What do you mean it won’t take new classes, you can add what you like into the code above..

    Do you want the above function to accept additional classes?

    Please clarify.. ??

    Thread Starter XLCowBoy

    (@xlcowboy)

    Hi Mark,

    Well, I’d like to be able to still accept $args really. I think the idea is something exactly like wp_page_menu(‘menu_class’ => ‘menu’).

    (Honestly, all I ever wanted to do was to replace the div with a nav, and retain all of wp_page_menu’s functions.)

    Is that not what the code you have above does already?

    I’m not sure i follow what the problem is with the code you have already, does it not have the desired effect?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Replace default div in wp_page_menu (PHP help)’ is closed to new replies.