skip to Main Content

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


  1. Just add the function by that name:

    function my_render_page() {
        echo '<h1>Hello World</h1>';
        echo '<p>This is a demo page for the T5 plugin.</p>';
    }
    
    Login or Signup to reply.
  2. Here’s how you can do it:

    // Check if we are on the plugin page with the slug 't5-demo'
    if (isset($_GET['page']) && $_GET['page'] === 't5-demo') {
        // Load your special PHP code here
        // This code will only be executed when the current page is the plugin page with the slug 't5-demo'
        // For example:
        echo 'This is special PHP code loaded only on the plugin page with the slug "t5-demo".';
    }
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search