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

Knowing that wordpress doesn't follow MVC pattern. What is the best way in worpress to output plugin's result in a certain url. lets say I would like to show "hello world" in main area under "www.example.com/show-hello-world" url. thanks. hope question is clear!

more details:

Let's say url "example.com/show-hello-world"

  1. how could I specify template name, let's say "page" ?
share|improve this question
create a page named "show hello world" ? – edelwater Mar 20 '11 at 23:20
Try rephrasing your question or give a better example of what you want to achieve – Bainternet Mar 21 '11 at 1:34

There are two steps:

function my_plugin_rewrite_rule() {
  global $wp;

  $wp->add_query_var( 'show_hello_world' );
  add_rewrite_rule( 'show-hello-world/?$', 'index.php?show_hello_world=1', 'top' );
add_action( 'init', 'my_plugin_rewrite_rule' );

That takes care of rewriting. Remember to flush the rewrite rules.

Now, your plugin can check for get_query_var( 'show_hello_world' ); and load a certain file:

function my_plugin_template( $path ) {
 if ( get_query_var( 'show_hello_world' ) )
    return locate_template( 'my-plugin.php' );
    return $path;
add_filter( 'template_include', 'my_plugin_template' );
share|improve this answer
A little more laconic way to create query var is add_rewrite_endpoint( 'show_hello_world', EP_ROOT ) (but the check would have to be slightly different since it won't be 1, but just "set" in query vars without anything else in URL after). – Rarst Oct 17 '14 at 21:24

In your header.php, page.php, or index.php, add:

if (is_page('show-hello-world')) { 
   echo "Hello, world!";
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.