[imp] [#33200] Improved if/else structure related to sidebar  (Fix
#2910)