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 want to use wordpress content in external mobile app. I need an URL address to get content from function located in functions.php for example:

function test()
     return 'it works';

What I need is an url address (http://example.com/something) which will return a value from function test. I hope that I wrote it clearly. Sorry for my language mistakes.

share|improve this question
up vote 0 down vote accepted

You can check for the presence of a specific query variable, so http://www.example.com?my_listener=test. You check for this on the init hook and if it isn't there you just quit early and WP goes about it's business. If it is there, you can then do something, just don't forget to exit at the end or the full page loads and that can mess up the response you are trying to send to your app.

    function wpa_91930() {
        // if query var is not present just return
        if ( ! isset( $_REQUEST['my_listener'] ) || 'test' != $_REQUEST['my_listener'] )

        // send response
        echo "it works";

       // don't forget to exit when you are done

    add_action( 'init', 'wpa_91930' );
share|improve this answer
Thank you, it works. Maybe you've got some idea to change url format from example.com?my_listener=test to example.com/test ? It just looks better :) – Paul Mar 22 '13 at 12:42
This might help with creating pretty URLs: wordpress.stackexchange.com/questions/12965/… – Pat J Mar 22 '13 at 13:59
If it is just an app that is collecting data, how the URL looks doesn't seem that important. But following Pat's link, should get you the appropriate rewrite rules. – helgatheviking Mar 22 '13 at 14:31
That's what I need. Thank's a lot. – Paul Mar 22 '13 at 14:37

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.