Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In Drupal, you can assign a URI to a function that gets called, like this:

function mymodule_menu() {
    return array(
        'custom_uri' => array(
            'page callback' => 'my_custom_function',
            [...]
        );
    );
}

This then tells Drupal to call the function my_custom_function whenever the url is http://www.mysite.com/custom_uri.

In Wordpress I'm trying to accomplish the same idea. I want to have a custom URI that somehow calls a function to render output.

From what I've found I can use WP_Rewrite to turn a permalink into a query string and then check for the query string in my plugin. Going that route, how would I display my own content in the site's theme?

The other option I've seen is to do it via a shortcode, but then that means either the user generates a page or I do it programmatically (and then probably use WP_Rewrite to set up a custom permalink). This seems messy and I'd rather the user not have to worry about doing any work.

Are there any more options?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Create an endpoint. That is a custom URL that will be handled by a callback.

Examples are How can I use WordPress functions in my stylesheet? and Is it possible to request several post types from a feed?. See also add_rewrite_endpoint() and A (Mostly) Complete Guide to the WordPress Rewrite API.

share|improve this answer
add comment

Your Answer

 
discard

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.