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.

1 Answer
1

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;

Leave a Reply

Your email address will not be published. Required fields are marked *