I have been using this for a while now with CP. Most of this code is originally from Jetpack widget visibility. I didn’t want to use jetpack but like the widget visibility options.
ClassicPress, control where widgets appear on your site
This plugin adds a visibility panel that lets you configure widgets to appear or be hidden only on certain pages.