目前我的Wordpress主题有一个链接到博客根页在管理顶部菜单,但我想在管理侧边栏下面的"仪表板"answers"配置文件"的链接。
我试过用
添加它add_menu_page( 'Course', 'Course', 'read', get_option('home'), 'home', 'dashicons-welcome-learn-more')
这会生成一个带有正确图标的链接,但是为该链接生成的url是:
http://localhost:8888/wp-admin/admin.php?page=http:/localhost:8888
我应该如何设置它来生成一个链接到:
http:/localhost:8888
add_menu_page
添加一个新的菜单项页面到Wordpress管理菜单。它不能有link,因为它不接受link作为参数。但是,我们可以在自定义回调函数中重定向。
[更新代码/]
这是完整的实现:
add_action('admin_menu', 'register_my_custom_menu_page');
function register_my_custom_menu_page() {
add_menu_page('Course', 'Course', 'read', get_option('home'), 'redirect_to_local_110', 'dashicons-welcome-learn-more');
}
function redirect_to_local_110() {
//hardcode URL
$url = "http://localhost:8888";
//OR
//If URL has to be the Home URL then it can be fetched using
//$url = get_option('home');
echo '<meta http-equiv="refresh" content="0; url='.$url.'" />';
exit;
}
我还更新了重定向到meta,因为使用wp_redirect通常会导致报头已经发送错误,而错误的原因是在调用该函数之前开始输出。