How can WordPress be configured to redirect links with specific IDs to URLs stored in a database without the need for additional PHP files?

To configure WordPress to redirect links with specific IDs to URLs stored in a database without additional PHP files, you can use the "template_redirect" action hook to check for the ID in the URL, query the database for the corresponding URL, and then perform a redirect using the "wp_redirect" function.

add_action('template_redirect', 'custom_redirect');

function custom_redirect() {
    if (is_numeric(get_query_var('p'))) {
        $id = get_query_var('p');
        $url = get_url_from_database($id);

        if ($url) {
            wp_redirect($url);
            exit;
        }
    }
}

function get_url_from_database($id) {
    // Implement your database query logic here to retrieve the URL based on the ID
    return $url;
}