Reputation: 131
Have a very quick question, and i presume simple, but as its late in the day, i can't seem to solve it...
I have a wordpress menu floated to the right. To correct the order, i need to display the menu in reverse. I am using this function to do this, and placing it just before the menu is called in header:
<?php add_filter( 'wp_nav_menu_objects', create_function( '$menu', 'return array_reverse( $menu );' ) ); ?>
As i only want to reverse one menu, i need to put a remove_filter after the menu... and can't figure it out... or maybe the add_filter function is wrong in the first place.
Any ideas? Thanks in advanced!
Upvotes: 1
Views: 1684
Reputation: 63556
WordPress’ plugin API offers no simple access to anonymous functions or closures.
Use a regular function as callback instead:
add_filter( 'wp_nav_menu_objects', 'reverse_menu' );
function reverse_menu( $menu ) {
remove_filter( current_filter(), __FUNCTION__ );
return array_reverse( $menu );
}
Never use create_function()
. It is slow, hard to debug, and it doesn’t work well with opcaches.
Upvotes: 2