How to assign a Permalink to a Function

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.

Read More

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?

Related posts

Leave a Reply

1 comment