YouTube is a great place for all your mainstream audio and video needs. But you can't simply plug in your headphones, choose a playlist, and put your phone back in your pocket without subscribing to YouTube Red, which costs $9.99/month for ad-free and background playback. If you can't afford that for just background playback, there are other ways.
If you're running Android KitKat, Lollipop, or Marshmallow, then you know there are Xposed modules which allow you to block ads on YouTube and enable background playback. However, Xposed hasn't been updated to support Android Nougat yet. There is another option of installing a modded version of YouTube, but some users don't trust modded apps from those they don't know. That leaves us with going it the manual way and modding the YouTube app ourselves.
In order to force YouTube to enable background playback on Android 7.0+, we'll simply need to "patch" the app. To do that, start by installing an app called Lucky Patcher, then open it up and grant root permissions.
Here comes the fun part... actually patching YouTube. When prompted, allow Lucky Patcher to update so that the latest patches will be available to you.
Next, select YouTube from the list, then hit "Open Menu of Patches." You might get a system application warning if YouTube is installed as a system app, so hit "Yes" if prompted. From here, tap "Custom patch," then hit "Apply." When you're done, just wait a couple of seconds as YouTube gets patched.
Tip: You can also block most ads on YouTube with Lucky Patcher—just use the "Remove Google Ads" option from this same menu.
Open up YouTube, select your song, playlist, or video of choice, and hit the back button until you're out of the app. YouTube background playback will immediately kick into effect, and a persistent notification will allow you to seek tracks (you can dismiss the Background play one—it'll only show up the first time you use background playback). Enjoy!
Screenshots by Kevin M./Gadget Hacks