0

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.

0

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'] )
            return;

        // send response
        echo "it works";

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

    add_action( 'init', 'wpa_91930' );

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.