admin管理员组

文章数量:1288016

I am creating a custom wordpress plugin.

Where for some pages like

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.

I am creating a custom wordpress plugin.

Where for some pages like

http://example/clinic

http://example/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.

Share Improve this question edited Feb 6, 2015 at 14:29 Mark Kaplun 23.7k7 gold badges43 silver badges65 bronze badges asked Feb 6, 2015 at 14:20 Balaji ChandrasekaranBalaji Chandrasekaran 1331 gold badge1 silver badge3 bronze badges 1
  • Can you provide more information? For example, what is $wp? Are you using that code in some action hook? If so, which one? – cybmeta Commented Feb 6, 2015 at 14:37
Add a comment  | 

1 Answer 1

Reset to default 3

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;

本文标签: How to get current page name in my wordpress plugin