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

Suppose I have written a hello world plugin, the main function is just print out a sting hello world.

I want to print out hello world when I access the URL likes http://example.com?plugin=helloworld

Is it possible to make the hello world plugin functional when I access a specific URL?

share|improve this question
up vote 2 down vote accepted

The Simplest way is to add a Query var to the list of query var that WordPress recognizes and check for that newly added query var on template redirect hook ex:

add_filter( 'query_vars', 'se67095_add_query_vars');

*   Add the 'my_plugin' query variable so WordPress
*   won't remove it.
function se67095_add_query_vars($vars){
    $vars[] = "my_plugin";
    return $vars;

*   check for  'my_plugin' query variable and do what you want if its there
add_action('template_redirect', 'se67905_my_template');

function se67905_my_template($template) {
    global $wp_query;

    // If the 'my_plugin' query var isn't appended to the URL,
    // don't do anything and return default
    if(!isset( $wp_query->query['my_plugin'] ))
        return $template;

    // .. otherwise, 
    if($wp_query->query['my_plugin'] == 'helloworld'){
        echo "hello world";

    return $template;
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.