Creating an endpoint in wordpress

You can create a custom endpoint using the add_feed function. I have used this in the past to create custom iCal feeds.

// Initialize the feed
function your_add_custom_feed() {
    // This adds a feed http://example.com/?feed=myfeed
    add_feed('myfeed', 'your_create_feed');
}
add_action('init','your_add_custom_feed');

// Create a function to form the output
function your_create_feed() {

    // Query variables are accessible here ($_GET)
    $myvar = get_query_var('myvar');

    // You may need to specify the header before output here depending on your type of feed
    // header(...)

    // Echo your feed here.

}

Leave a Comment