How to call custom plugin function directly from browser URL

Solution:1

I found, we can create rest api and use it, here what i did with rest api Need to use it with this URL : http://localhost/wordpress-o/wp-json/my-route/my-phrase

function my_register_route() {
    register_rest_route('my-route', 'my-phrase', array(
        'methods' => 'GET',
        'callback' => 'custom_phrase',
            )
    );
}
function custom_phrase() {
    return rest_ensure_response('Hello World! This is my first REST API');
}

add_action('rest_api_init', 'my_register_route');

Solution:2

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