Forums

Replace default div in wp_page_menu (PHP help) (4 posts)

  1. XLCowBoy
    Member
    Posted 1 year ago #

    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?

  2. Mark / t31os
    Moderator
    Posted 1 year ago #

    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.. :)

  3. XLCowBoy
    Member
    Posted 1 year ago #

    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.)

  4. Mark / t31os
    Moderator
    Posted 1 year ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic