aiddev
aiddev

Reputation: 1429

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

Upvotes: 0

Views: 524

Answers (3)

Mansukh Khandhar
Mansukh Khandhar

Reputation: 2582

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;
}

Upvotes: 1

Mansukh Khandhar
Mansukh Khandhar

Reputation: 2582

Add custom logo in admin menu.

http://screencast.com/t/dCvqzfxdup

add_action('admin_menu', 'codyfly_admin_menu');

function codyfly_admin_menu() {
    global $menu;
    $url = 'http://codyfly.com';
    $url1 = 'http://codyfly.com';
    $menu[0] = array( __(''), 'read', $url, 'my-logo', 'my-logo');
    $menu[1] = array( __(''), '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 style here

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

#adminmenu a.shomtek-logo div.wp-menu-name {
    display: none;
}

Upvotes: 1

Mansukh Khandhar
Mansukh Khandhar

Reputation: 2582

For Add new menu in admin : using add_menu_page we can add menu and add_submenu_page to add sub menu. More detail

Below snippet to add admin new custom menu

add_action('admin_menu', 'register_event_menu');
function register_event_menu() {
    add_menu_page('Event', 'Event', 'manage_options', 'event_details', 'event_function', 'dashicons-clipboard');
    add_submenu_page('event_details', 'Event Setting', 'Event Setting', 'manage_options', 'event_setting', 'event_settings_function');
}

function event_function() {

    echo "<div class='warp'>";
    echo "<h2>Admin Page DalwadiWp</h2>";
    echo "</div>";
}

function event_settings_function() {
    echo "<div class='warp'>";
    echo "<h2>Admin Page DalwadiWp</h2>";
    echo "</div>";

}

For remove menu in admin list. Below snippet to remove Post menu in admin list. More detail

add_action( 'admin_menu', 'custom_menu_page_removing' );
function custom_menu_page_removing() {
    remove_menu_page( 'edit.php' ); //Posts
}

Upvotes: 1

Related Questions