how do i create a specific handler for a url?

You could use the parse_request hook. For example:

add_action( 'parse_request', function ( $wp ) {
    // Run your actions only if the current request path is exactly 'image-generator'
    // as in https://example.com/image-generator if the site URL is https://example.com
    if ( 'image-generator' === $wp->request ) {
        $a   = $_GET['a'];
        $b   = $_GET['b'];
        $etc="etc";
        // ... your code here.

        // And then send the HTTP status and also the Content-Type headers.
        status_header( 200 );
        header( 'Content-Type: image/jpeg' );
        // ... echo your image.

        exit;
    }
} );

And note that status_header() is a WordPress function for sending HTTP status header. See the documentation for more details.

Leave a Comment