2

I am creating a custom wordpress plugin.

Where for some pages like

http://example.com/clinic

http://example.com/pharmacy

i will append my template code from my plugin folder. Which mean i will include my custom template not even related to wordpress theme.

my code will look like this inside my wordpress plugin page.

if ( $wp->query_vars('pagename')=="clinic"){            
    include(MYPLUGINPATH . '/template/clinic.php');
    die();
}else if($wp->query_vars('pagename')=="pharmacy"){
    include(MYPLUGINPATH . '/template/clinic.php');
    die();
}

But $wp-query_vars('pagename') return null.is there a way to get the current loading wordpress pagename inside the plugin code.

  • Can you provide more information? For example, what is $wp? Are you using that code in some action hook? If so, which one? – cybmeta Feb 6 '15 at 14:37
2

Use the $pagename global variable or pull it from the url

$slug = basename(get_permalink());

or grab the title before the loop starts:

$page_title = $wp_query->post->post_title;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.