How to activate “Description” metabox for menu item programmatically?

I’m creating custom wordpress theme. How can I enable “Description” metabox for menu items (on nav-menu page) by default programmatically?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Remove the description from the user meta value managenav-menuscolumnshidden:

add_filter( 'manage_nav-menus_columns', 'enable_nav_menu_description_by_default' );

function enable_nav_menu_description_by_default( $columns )
{
    $desc_key = 'managenav-menuscolumnshidden';
    $hidden   = get_user_option( $desc_key );
    $user_id  = wp_get_current_user()->ID;

    if ( ! $hidden )
    {
        update_user_option(
            $user_id,
            $desc_key,
            array ( 0 => 'link-target', 1 => 'css-classes', 2 => 'xfn' )
        );
    }
    elseif ( FALSE !== ( $key = array_search( 'description', $hidden ) ) )
    {
        unset( $hidden[ $key ] );
        update_user_option( $user_id, $desc_key, $hidden );
    }

    return $columns;
}

Method 2

If you’re looking to output the menu description here is a useful tutorial using WordPress Walker Menu class to enchance the menu WordPress Walker Menu Tutorial


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x