How to register a middleware?

I’ve created a middleware class for displaying the admin-bar on custom routes:

<?php

declare(strict_types=1);

namespace App\Middleware;

use Closure;
use Illuminate\Http\Request;

class WordPress
{
	/**
	 * Makes sure the 'template_redirect' action is executed when using custom routes.
	 * The 'template_redirect' action is required for displaying the WP_Admin_Bar.
	 */
	public function handle(Request $request, Closure $next)
	{
		do_action('template_redirect');

		return $next($request);
	}
}

To use it, add the middleware to your route like this:

Route::get('/route', 'Path\To\Controllers\Controller@show')->middleware(['web', WordPress::class]);