Steve Taylor photo

Force display of description field in WordPress menus

A very small but very good discovery I made at this year’s WordCamp Portsmouth was thanks to Robert O’Rourke. I never knew that if you folded down the Screen Options at the top of the Appearance > Menus admin screen in WordPress, you get a few extra fields for menu items. They’re hidden by default.

The big one for me is “Description”. I’ve often used a menu for managing the items (i.e. posts and pages) that are featured in a carousel on the home page of a site. I wrote my own code to populate the menu query with information from the posts the menu items refer to—specifically, a description or extract to use as teaser text. Well, this little discovery that I can allow clients to set (or override) the teaser text right there while they’re managing the carousel “menu” is small; but I think little things like this really help clients when they’re busy managing their site.

But if you have to explain to them to open Screen Options and check a box to do something that might be important, it’s two steps forward and one step back. A bit better, but not ideal.

What if you could force “Description” to be checked?

Here’s how:

add_filter( 'get_user_option_managenav-menuscolumnshidden', 'slt_nav_menus_columns_hidden' );
function slt_nav_menus_columns_hidden( $result ) {
	if ( in_array( 'description', $result ) )
		unset( $result[ array_search( 'description', $result ) ] );
	return $result;
}

These Screen Options are stored in user preferences, so you need to filter a specific user option. Look here to see where this filter is being applied in the core. You’ll see the option that’s passed here. The $screen->id is basically the admin file being viewed, with .php stripped off. These pointers should get you going working out how this all works to adapt the above code.

The callback hooked onto the filter just checks to see if description is in the list of hidden fields, and takes it out if it is.

Hey presto, the description field is always on!

Leave a comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>