get_template_part in admin

I am trying to use get_template_part when creating a page in the admin section of my site. However, it does not seem to be working. Does this function not work in the admin section? What alternative can I use?

Related posts

1 comment

  1. Yes, get_template_part() does work on Admin pages. Here is how I tested:

    Add this to functions.php theme (or child theme) file:

    add_action( 'admin_menu', 'wpse_99662_register_admin_test_page' );
    
    function wpse_99662_register_admin_test_page() {
        add_menu_page(
            'Admin Test Page',
            'Admin Test Page',
            'manage_options',
            'admin_test_page',
            'wpse_99662_admin_test_page'
        );
    }
    
    function wpse_99662_admin_test_page() {
        echo '<h2>Admin Test Page</h2>';
    
        get_template_part( 'admin', 'test' );
    }
    

    The admin-test.php file contains the following:

    <?php
    
    echo "Loaded admin-test.php<br />";
    

Comments are closed.