【问题标题】:Fatal error: Uncaught Error: Call to undefined function add_action() Error致命错误:未捕获错误:调用未定义函数 add_action() 错误
【发布时间】:2017-09-08 08:40:49
【问题描述】:

我面临以下错误: 致命错误:未捕获错误:调用未定义函数 add_action()

这是我的代码

function testtheme_add_admin_page(){
     add_menu_page( 'testtheme custom options', 'testtheme', 'manage_options', 
'testtheme_theme_create_page', 'dashicons-admin-generic', 110 );
}

add_action( 'admin_menu', 'testtheme_add_admin_page' );

function testtheme_theme_create_page(){
    //create custom options page
}

【问题讨论】:

  • 在插件文件中?还是在functions.php中?
  • 在functions.php中

标签: wordpress function


【解决方案1】:

我认为在执行任何函数之前,您需要先调用 wp-load.php 文件。

只需在文件顶部调用以下行并重试:

require(dirname(__FILE__) . '/wp-load.php');

dirname(__FILE__) 指向 WordPress 根目录,例如 www.yourdomain.com/wordpress/

希望这对您有所帮助。谢谢。

【讨论】:

    【解决方案2】:

    兄弟,你刚刚没有把 menu-slug 放在那里

    function testtheme_add_admin_page(){
    add_menu_page( 'testtheme custom options', 'testtheme', 'manage_options', 
    'testtheme',    
    'testtheme_theme_create_page', 'dashicons-admin-generic', 110 );
    }
    
    add_action( 'admin_menu', 'testtheme_add_admin_page' );
    
    function testtheme_theme_create_page(){
     //create custom options page
    echo "test";    
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 2019-05-22
      • 2017-01-27
      • 2016-04-07
      • 2017-08-19
      • 2018-01-18
      相关资源
      最近更新 更多