WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
You'll need a url rewrite. – Rutwick Gangurde May 2 '12 at 5:01
Gotcha. Is hook_rewrite_rules the best place for that? – kidrobot May 2 '12 at 5:32
Check my answer over here... should give you an idea... wordpress.stackexchange.com/questions/34291/… – Rutwick Gangurde May 2 '12 at 6:00

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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