1

I have a function in functions.php like so:

function myplugin_mycallback($id) {
  // do something
}

I want this function called whenever a URL like myplugin/mycallback/xxx is accessed.

How/where do I define this path so it doesn't generate a 404?

2

You can use add_feed( $url, $callback ). Despite its name it sends a text/html Content-Type.

Basic example:

add_action( 'init', 'wpse_50841_register_extra_page' );

function wpse_50841_register_extra_page()
{
    add_feed( 'wpse50841', 'wpse_50841_callback' );
}

function wpse_50841_callback()
{
    print '<p>It works!</p>';
}

Visit the permalink settings page once to refresh the rewrite cache, and go to example.com/wpse50841/ or example.com/?feed=wpse50841 to see your code in action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.