Title: Replace default div in wp_page_menu (PHP help)
Last modified: August 19, 2016

---

# Replace default div in wp_page_menu (PHP help)

 *  [XLCowBoy](https://wordpress.org/support/users/xlcowboy/)
 * (@xlcowboy)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/replace-default-div-in-wp_page_menu-php-help/)
 * 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)

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/replace-default-div-in-wp_page_menu-php-help/#post-1678923)
 * 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](https://wordpress.org/support/users/xlcowboy/)
 * (@xlcowboy)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/replace-default-div-in-wp_page_menu-php-help/#post-1679105)
 * 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.)
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/replace-default-div-in-wp_page_menu-php-help/#post-1679367)
 * 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.

## Tags

 * [variables](https://wordpress.org/support/topic-tag/variables/)
 * [wp_page_menu](https://wordpress.org/support/topic-tag/wp_page_menu/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 3 replies
 * 2 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/replace-default-div-in-wp_page_menu-php-help/#post-1679367)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
