Removing posts and comments from WordPress

You need to “hook” it to an action, in this case admin_menu:

add_action( 'admin_menu', 'remove_admin_menus' );

Just place it right after the function.