I Successfully Solved it and done making The Requirement in easy way ‘that’s i found for now’
i added a js file inside my theme folder with this name “admin.js”
i called this file from theme function with this code
// replace # with js file link
// custom admin menu js
add_action( 'admin_enqueue_scripts', 'my_enqueue' );
function my_enqueue() {
if(is_admin()){
wp_register_script( 'custom-js', 'my js file link');
wp_enqueue_script('custom-js');
}
}
// style for removing floating submenu and make it inside sidbbar
jQuery(document).ready(function($){
$('#adminmenu .wp-not-current-submenu .wp-submenu').append(`<style>
#adminmenu .wp-not-current-submenu .wp-submenu {
position: relative;
min-width:auto;
left:auto;
top: auto;
box-shadow:none;
display:none;
}
</style>`);
// this Code to make menu show/ hide the submenu on click
$('#adminmenu > li.wp-has-submenu').click(function(e) {
// element to toggle
var $el = $('ul',this);
// after clicking any other menu item slide up other elements
$('#adminmenu > li.wp-has-submenu > ul').not($el).slideUp();
// toggle element
$el.stop(true, true).slideToggle(400);
return false;
});
// stop events from bubbling from sub menu clicks
$('#adminmenu > li.wp-has-submenu > ul > li').click(function(e) {
e.stopPropagation();
});
}); // end of jquery code