In my Plugin, I have an object 'Settings' (to display stuff in Wordpress settings).



namespace FooNamespace\Admin\Settings;

class Settings {

    public $menu_slug;

    public function __construct(){

        $this->menu_slug = 'settings-'.PLUGIN_DOMAIN ;

        // Initialize the component


    protected function init(){

        // output method
        add_action( '_output_content_submenu_page_' . $this->menu_slug, array( $this, 'html_page_template' ) );

    public function html_page_template(){

        include_once 'views/view-settings.php';



In 'view-settings.php', I can normally use all basic wordpress functions.


<div class="wrap">

    <h1 class="wp-heading-inline">
        <?php _e('Settings for '.PLUGIN_TITLE, PLUGIN_DOMAIN); ?>
    <hr wp-header-end />

    <h2 class="nav-tab-wrapper">

    <?php foreach ($tabs as $tab ){ ?>
            <?php include_once $tab["path"]; ?>
    <?php } ?>


But in my included file ( include_once $tab["path"]; ), I cannot use the wordpress function like __() or _e().

Included file

<form id="form-settings-recaptach" method="post">
    <table class="widefat fixed">
                    <label class="label"><?php _e( "Foo", PLUGIN_DOMAIN ); ?></label>

So I get this error :

Fatal error: Uncaught Error: Call to undefined function _e()

Notice : if I include the child php file directly inside Settings.php, the functions are called. So It's a real problem of include inside an iclude and levels for Wordpress

Why ? How can I debug this ?

  • The _e('Settings for '.PLUGIN_TITLE, PLUGIN_DOMAIN); working in the view-settings.php? another way, use require_once for include your file. Sep 25, 2017 at 10:43
  • where is called the action _output_content_submenu_page_... ?
    – mmm
    Sep 25, 2017 at 10:47
  • Yes, the _e('Settings for '.PLUGIN_TITLE, PLUGIN_DOMAIN) works. Ok, I will try with require_once. For the action '_output_content_submenu_page_', it's called in an other object which make the submenu page.
    – J.BizMai
    Sep 25, 2017 at 10:58
  • Same problem with require_once.
    – J.BizMai
    Sep 25, 2017 at 11:00

2 Answers 2


I've had this problem in past

try using include with locate_template: I don't exactly remember the reason but this code still works:

Example: include(locate_template(YOUR_TEMPLATE_PATH));

Here's a complete demonstration too, using the same idea, if you need more help.

For Admin Panel

include simply works in admin panel.

You might want to modify your code like:

public function init(){
    add_menu_page( 'Your Plugin Name' , 'Your Plugin Settings' , 'manage_options' , 'your_plugin_settings' ,  array( $this, 'settings_page' ) );
public function html_page_template(){
    $html = ob_get_clean();
    echo $html;

If the init function is calling your custom hook, then please don't modify it and make sure that code is working properly. Your html_page_template function should now output the form.

  • locate_template => "Retrieve the name of the highest priority template file that exists.". I am in admin > Settings > My PLugin Name, I do not use any template like 'page.php' at this location. So unfortunately, that does not work. I have any response from this function :/
    – J.BizMai
    Sep 25, 2017 at 11:42
  • Thank you for your answer about Admin panel, but it's already like this ^^
    – J.BizMai
    Sep 25, 2017 at 14:55
  • I see that you're not using 'echo' to print the markup. Would you please post the updated code and the function hook '_output_content_submenu_page_' . $this->menu_slug. If still you think it's not helping then please check this template. Though I've tested my code and it works. There must be some error in other files which you haven't posted.
    – Akash K.
    Sep 25, 2017 at 16:55

I found the problem and I have the solution : To include the child file, as I'm working on localhost I changed the path :

My error :

 plugin_dir_path( __FILE__ ).'my-child-template.php' //<-- \path\to\file/my-child-template.php

 //Changed by
 plugin_dir_url( __FILE__ ).'my-child-template.php' //<-- http://localhost/wordpress/wp-content/plugins/my-plugin/path/to/file/my-child-template.php

With the second path, it worked on localhost, it managed to include the template but impossible to call worpdress functions.

So, I had to find a solution to include the path file instead of the url but with a localhost compatibility.

The solution is :

public function html_page_template(){
    $ipAddress = gethostbyname($_SERVER['SERVER_NAME']);
    if( $ipAddress === ""){
        $base_path =  dirname( __FILE__ )."\\templates\\";
        $base_path = plugin_dir_path( __FILE__ )."templates/";
    $a_settings_tab = array( 
        0 => array(
            "key" => "foo",
            "path" =>  $base_path ."foo.php"
        1 => array(
            "key" => "bar",
            "path" =>  $base_path ."bar.php"

    include_once 'views/view-settings.php';
    $html = ob_get_clean();
    echo $html;
  • sorry, but this doesn't make much sense, And if you are actually including a url, it is totally wrong. Sep 25, 2017 at 15:50
  • Yes, that was wrong to include an url, I had to include the path file. It's exactly I'm explaining in this solution.
    – J.BizMai
    Sep 25, 2017 at 16:58
  • ok, so the problem was with your question, still trying to detect on which server the code run is wrong by itself Sep 25, 2017 at 17:05
  • How is someone supposed to know where the error was with a question like that?
    – Akash K.
    Oct 6, 2017 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.