- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 add_menu_page 添加了一个菜单,该菜单一切正常,但单击时我希望此菜单页面打开特定帖子 ID 的帖子编辑器。
作为概念证明,我尝试将 javascript 重定向回显到 do 函数中,如下所示...
// Load up the menu page
function register_availability_custom_menu_page() {
add_menu_page('custom menu title', 'Availability', 'add_users', 'options', 'options_do_page');
}
function options_do_page() {
echo "<script type=\"text/javascript\">";
echo "window.location = '/whatever_page.php';";
echo "</script>";
}
这种方法确实有效,但我想知道这是否是最好的方法,是否有更好的方法来重定向到我所在的页面?
我现在也尝试使用 wp_redirect 与此代码...
add_action( 'admin_menu' , 'admin_menu_new_items' );
function admin_menu_new_items() {
wp_redirect( home_url() );
exit;
}
这给了我一个标题已发送错误,有人可以建议我哪里出错了吗?
最佳答案
如果我理解正确,那么您不需要重定向。而不是在函数 add_menu_page
中使用 $menu_slug
,输入目标页面的地址,例如:
$the_post_title = 'The Portfolio';
add_action( 'admin_menu', 'wpse_59050_add_menu' );
function wpse_59050_add_menu()
{
global $the_post_title;
$our_page = get_page_by_title( $the_post_title );
$settings_page = add_menu_page(
'Edit '.$our_page->post_title,
'Edit '.$our_page->post_title,
'add_users',
'/post.php?post='.$our_page->ID.'&action=edit',
'',
'',
2
);
}
该函数来自以下 WordPress 答案:Highlighting a Menu Item by Post Name 。您需要一些 jQuery 来正确突出显示该顶级菜单,请检查我和 TheDeadMedic 在该问题中的答案。
关于wordpress - 从 add_menu_page 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11419028/
我正在尝试使用 add_menu_page 创建自定义“custom_post”页面。 (这是否已经是一个错误?:-/) 这是行不通的代码: add_menu_page( 'projets' , 'p
我使用 add_menu_page 添加了一个菜单,该菜单一切正常,但单击时我希望此菜单页面打开特定帖子 ID 的帖子编辑器。 作为概念证明,我尝试将 javascript 重定向回显到 do 函数中
我最近进入了 WordPress 插件开发,我想添加一个菜单页面(左侧菜单中的链接)。以前的 SO 问题和 WordPress 法典说它就像调用一样简单: add_menu_page( $page_t
基本上,我正在为我的 WordPress 网站制作一个小插件,我遇到了我能找到的最烦人的问题,我目前的结构是这样的/wp-content/plugins/videos/videos.php PHP 文
我是一名优秀的程序员,十分优秀!