aidaghazaryan aidaghazaryan - 2 months ago 7
jQuery Question

how to change sidebar menu content dynamically - wordpress?

I have unique design of wordpress backend and need to implement it. How can I add my own menu items there(see first attached image)? I know how to remove existing menus, but except removing I need to add my own menus. Is there a dynamic way with php to do it? (see image example here)

I tried to add my custom menus with jquery append() function but it is really bad solution. Any ideas please?

Wordpress Admin Side Menu

Answer

Add custom logo with user name in admin menu.

Demo link image : http://screencast.com/t/W8dcfhAgS

Add in functions file

add_action('admin_menu', 'codyfly_admin_menu');
function codyfly_admin_menu() {
    global $menu;
    global $current_user;
    $url = 'http://codyfly.com';
    $url1 = 'http://codyfly.com';
    $username = '';
    if ( is_user_logged_in() ) { 
        $username = $current_user->user_login;
    }
    $menu[0] = array( __(''), 'read', $url, 'my-logo', 'my-logo');
    $menu[1] = array( __($username), 'read', $url1, 'my-logo1', 'my-logo1');
}

add_action('admin_head', 'codyfly_admin_style');

function codyfly_admin_style() {
    echo '<link rel="stylesheet" href="' . get_template_directory_uri() . '/css/style-admin.css" type="text/css" media="all" />';
}

Add in style

#adminmenu a.my-logo,
#adminmenu a.my-logo1{
    display: block;
    background: url(https://dummyimage.com/140x40/fff/000) no-repeat center center;
    background-size: 140px 40px;
    width: 140px;
    height: 40px;
    margin: 0 auto;
    padding: 10px 5px;

    font-size: 14px;
    font-weight: 400;
    line-height: 18px;
}
#adminmenu a.my-logo1{
     background: url(https://dummyimage.com/50x40/fff/000) no-repeat;
    background-position: left center;
    background-size: 50px 40px;
}
#adminmenu a.my-logo1 .wp-menu-name{
    padding-left: 60px;
}
#adminmenu a.shomtek-logo div.wp-menu-name {
    display: none;
}