i write this code:
$hook = add_menu_page(
'T5 Demo', // page title
'T5 Demo', // menu title
'manage_options', // capability
't5-demo', // menu slug
'my_render_page' // callback function
);
how to load one php code only this above menu page slug?
thanks
2
Answers
Just add the function by that name:
Here’s how you can do it:
Explanation:
We check if the
$_GET['page']
parameter is set, which represents the current page slug in the WordPress admin menu.We compare the value of
$_GET['page']
with the slug of your plugin page, which is ‘t5-demo’ in this case.If the current page slug matches ‘
t5-demo
‘, we execute the special PHP code inside the if block.Inside the if block, you can include or execute any PHP code specific to your plugin page.