Can I call a custom plugin with a direct URL

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";
        exit;
    }

    return $template;
}

Leave a Comment